@opensea/sdk 12.15.0 → 13.0.1

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 (88) hide show
  1. package/lib/abi/abis.d.ts +0 -30
  2. package/lib/abi/abis.js +1 -29
  3. package/lib/abi/abis.js.map +1 -1
  4. package/lib/api/accounts.js.map +1 -1
  5. package/lib/api/api.d.ts +3 -0
  6. package/lib/api/api.js +4 -0
  7. package/lib/api/api.js.map +1 -1
  8. package/lib/api/apiPaths.d.ts +2 -0
  9. package/lib/api/apiPaths.js +9 -1
  10. package/lib/api/apiPaths.js.map +1 -1
  11. package/lib/api/assets.js.map +1 -1
  12. package/lib/api/chains.js.map +1 -1
  13. package/lib/api/collections.js.map +1 -1
  14. package/lib/api/drops.js.map +1 -1
  15. package/lib/api/events.js.map +1 -1
  16. package/lib/api/listings.js.map +1 -1
  17. package/lib/api/nfts.js.map +1 -1
  18. package/lib/api/offers.js.map +1 -1
  19. package/lib/api/orders.js.map +1 -1
  20. package/lib/api/search.js.map +1 -1
  21. package/lib/api/signals.d.ts +21 -0
  22. package/lib/api/signals.js +31 -0
  23. package/lib/api/signals.js.map +1 -0
  24. package/lib/api/tokens.js.map +1 -1
  25. package/lib/api/tools.js.map +1 -1
  26. package/lib/api/transactions.js.map +1 -1
  27. package/lib/api/types.d.ts +18 -1
  28. package/lib/api/types.js.map +1 -1
  29. package/lib/api/uploadContext.js.map +1 -1
  30. package/lib/api/walletAuth.d.ts +264 -259
  31. package/lib/api/walletAuth.js +17 -10
  32. package/lib/api/walletAuth.js.map +1 -1
  33. package/lib/auth/index.js.map +1 -1
  34. package/lib/auth/oauth.d.ts +3 -1
  35. package/lib/auth/oauth.js +47 -30
  36. package/lib/auth/oauth.js.map +1 -1
  37. package/lib/auth/siwx.js.map +1 -1
  38. package/lib/index.js.map +1 -1
  39. package/lib/orders/attribution.js.map +1 -1
  40. package/lib/orders/erc20Fulfillment.js.map +1 -1
  41. package/lib/orders/orderUseCase.js.map +1 -1
  42. package/lib/orders/privateListings.js.map +1 -1
  43. package/lib/orders/types.js.map +1 -1
  44. package/lib/orders/utils.js.map +1 -1
  45. package/lib/provider/ethers-adapter.js.map +1 -1
  46. package/lib/provider/seaport-bridge.js.map +1 -1
  47. package/lib/provider/viem-adapter.js.map +1 -1
  48. package/lib/scopes.js.map +1 -1
  49. package/lib/sdk/assets.d.ts +6 -5
  50. package/lib/sdk/assets.js +24 -36
  51. package/lib/sdk/assets.js.map +1 -1
  52. package/lib/sdk/base.d.ts +8 -8
  53. package/lib/sdk/base.js.map +1 -1
  54. package/lib/sdk/cancellation.js.map +1 -1
  55. package/lib/sdk/fulfillment.js.map +1 -1
  56. package/lib/sdk/orders.js.map +1 -1
  57. package/lib/sdk/tokens.js.map +1 -1
  58. package/lib/sdk.js.map +1 -1
  59. package/lib/stream/client.js.map +1 -1
  60. package/lib/stream/helpers.js.map +1 -1
  61. package/lib/stream/transport/phoenix.js.map +1 -1
  62. package/lib/stream/types.js.map +1 -1
  63. package/lib/types.js.map +1 -1
  64. package/lib/utils/address.js.map +1 -1
  65. package/lib/utils/case.js.map +1 -1
  66. package/lib/utils/chain.d.ts +1 -1
  67. package/lib/utils/chain.js.map +1 -1
  68. package/lib/utils/dateHelper.js.map +1 -1
  69. package/lib/utils/eip712.js.map +1 -1
  70. package/lib/utils/fees.js.map +1 -1
  71. package/lib/utils/fetchTransport.js.map +1 -1
  72. package/lib/utils/protocol.js.map +1 -1
  73. package/lib/utils/rateLimit.js +3 -3
  74. package/lib/utils/rateLimit.js.map +1 -1
  75. package/lib/utils/stringHelper.js.map +1 -1
  76. package/lib/utils/units.js.map +1 -1
  77. package/lib/utils/utils.js.map +1 -1
  78. package/lib/viem.js.map +1 -1
  79. package/package.json +3 -4
  80. package/src/abi/abis.ts +0 -29
  81. package/src/api/api.ts +4 -0
  82. package/src/api/apiPaths.ts +8 -0
  83. package/src/api/signals.ts +33 -0
  84. package/src/api/types.ts +22 -0
  85. package/src/api/walletAuth.ts +26 -18
  86. package/src/auth/oauth.ts +86 -53
  87. package/src/sdk/assets.ts +30 -54
  88. package/src/utils/rateLimit.ts +3 -3
package/src/sdk/assets.ts CHANGED
@@ -3,15 +3,10 @@ import {
3
3
  ERC20_ABI,
4
4
  ERC721_ABI,
5
5
  ERC1155_ABI,
6
- MULTICALL3_ABI,
7
6
  SET_APPROVAL_FOR_ALL_ABI,
8
7
  TRANSFER_HELPER_ABI,
9
8
  } from "../abi/abis"
10
- import {
11
- MAX_UINT256,
12
- MULTICALL3_ADDRESS,
13
- TRANSFER_HELPER_ADDRESS,
14
- } from "../constants"
9
+ import { MAX_UINT256, TRANSFER_HELPER_ADDRESS } from "../constants"
15
10
  import {
16
11
  type Amount,
17
12
  type AssetWithTokenStandard,
@@ -299,7 +294,7 @@ export class AssetsManager {
299
294
  if (unapprovedAssets.length > 0) {
300
295
  throw new Error(
301
296
  `The following asset(s) are not approved for transfer to the OpenSea conduit:\n${unapprovedAssets.join("\n")}\n\n` +
302
- `Please approve these assets before transferring. You can use the batchApproveAssets() method to approve multiple assets efficiently in a single transaction.`,
297
+ `Please approve these assets before transferring. You can use the batchApproveAssets() method to approve them.`,
303
298
  )
304
299
  }
305
300
 
@@ -336,16 +331,17 @@ export class AssetsManager {
336
331
 
337
332
  /**
338
333
  * Batch approve multiple assets for transfer to the OpenSea conduit.
339
- * This method checks which assets need approval and batches them efficiently:
340
- * - 0 approvals needed: Returns early
341
- * - 1 approval needed: Sends single transaction
342
- * - 2+ approvals needed: Uses Multicall3 to batch all approvals in one transaction
334
+ * Sends one approval transaction per token contract that is not yet
335
+ * approved, skipping contracts that already are. Each approval is sent from
336
+ * `fromAddress`, because a token grants an approval to `msg.sender`: routing
337
+ * them through a batching contract such as Multicall3 would approve that
338
+ * contract instead of the owner.
343
339
  *
344
340
  * @param options
345
341
  * @param options.assets Array of assets to approve for transfer
346
342
  * @param options.fromAddress The address that owns the assets
347
343
  * @param options.overrides Transaction overrides, ignored if not set.
348
- * @returns Transaction hash of the approval transaction, or undefined if no approvals needed
344
+ * @returns Hash of the last approval transaction, or undefined if no approvals needed
349
345
  *
350
346
  * @throws Error if the fromAddress is not available through wallet or provider.
351
347
  */
@@ -444,52 +440,30 @@ export class AssetsManager {
444
440
  return undefined
445
441
  }
446
442
 
447
- // Single approval: send directly using the signer
448
- if (approvalsNeeded.length === 1) {
449
- const { target, callData } = approvalsNeeded[0]
450
- const wallet = this.context.wallet
451
- if (!("signer" in wallet)) {
452
- throw new Error("A signer is required to approve assets")
453
- }
454
- const tx = await wallet.signer.sendTransaction({
455
- to: target,
456
- data: callData,
457
- from: fromAddress,
458
- overrides: overrides as Record<string, unknown>,
459
- })
460
-
461
- await this.context.confirmTransaction(
462
- tx.hash,
463
- EventType.ApproveAllAssets,
464
- "Approving asset for transfer",
465
- )
466
-
467
- return tx.hash
443
+ const wallet = this.context.wallet
444
+ if (!("signer" in wallet)) {
445
+ throw new Error("A signer is required to approve assets")
468
446
  }
469
447
 
470
- // Multiple approvals: use Multicall3
471
- const calls = approvalsNeeded.map(({ target, callData }) => ({
472
- target,
473
- allowFailure: false,
474
- callData,
475
- }))
476
-
448
+ let lastHash: string | undefined
477
449
  try {
478
- const transaction = await cc.writeContract({
479
- address: MULTICALL3_ADDRESS,
480
- abi: MULTICALL3_ABI,
481
- functionName: "aggregate3",
482
- args: [calls],
483
- overrides: { ...overrides, from: fromAddress },
484
- })
485
-
486
- await this.context.confirmTransaction(
487
- transaction.hash,
488
- EventType.ApproveAllAssets,
489
- `Batch approving ${approvalsNeeded.length} asset(s) for transfer`,
490
- )
450
+ for (const [index, { target, callData }] of approvalsNeeded.entries()) {
451
+ const tx = await wallet.signer.sendTransaction({
452
+ to: target,
453
+ data: callData,
454
+ from: fromAddress,
455
+ overrides: overrides as Record<string, unknown>,
456
+ })
491
457
 
492
- return transaction.hash
458
+ await this.context.confirmTransaction(
459
+ tx.hash,
460
+ EventType.ApproveAllAssets,
461
+ approvalsNeeded.length === 1
462
+ ? "Approving asset for transfer"
463
+ : `Approving asset ${index + 1} of ${approvalsNeeded.length} for transfer`,
464
+ )
465
+ lastHash = tx.hash
466
+ }
493
467
  } catch (error) {
494
468
  console.error(error)
495
469
  this.context.dispatch(EventType.TransactionDenied, {
@@ -498,6 +472,8 @@ export class AssetsManager {
498
472
  })
499
473
  throw error
500
474
  }
475
+
476
+ return lastHash
501
477
  }
502
478
 
503
479
  /**
@@ -92,9 +92,9 @@ export async function executeWithRateLimit<T>(
92
92
 
93
93
  // Check if this is a rate limit error by status code (robust) or retry-after header
94
94
  const isRateLimitError =
95
- rateLimitError.statusCode === RATE_LIMIT_STATUS_CODE ||
96
- rateLimitError.statusCode === CUSTOM_RATE_LIMIT_STATUS_CODE ||
97
- rateLimitError.retryAfter !== undefined
95
+ rateLimitError?.statusCode === RATE_LIMIT_STATUS_CODE ||
96
+ rateLimitError?.statusCode === CUSTOM_RATE_LIMIT_STATUS_CODE ||
97
+ rateLimitError?.retryAfter !== undefined
98
98
 
99
99
  if (!isRateLimitError || attempt === maxRetries) {
100
100
  // Not a rate limit error or out of retries, throw the error