@opensea/sdk 13.0.0 → 13.0.2

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 (68) hide show
  1. package/lib/abi/abis.d.ts +18 -11
  2. package/lib/abi/abis.js +11 -4
  3. package/lib/abi/abis.js.map +1 -1
  4. package/lib/api/accounts.js.map +1 -1
  5. package/lib/api/api.js.map +1 -1
  6. package/lib/api/apiPaths.js.map +1 -1
  7. package/lib/api/assets.js.map +1 -1
  8. package/lib/api/chains.js.map +1 -1
  9. package/lib/api/collections.js.map +1 -1
  10. package/lib/api/drops.js.map +1 -1
  11. package/lib/api/events.js.map +1 -1
  12. package/lib/api/listings.js.map +1 -1
  13. package/lib/api/nfts.js.map +1 -1
  14. package/lib/api/offers.js.map +1 -1
  15. package/lib/api/orders.js.map +1 -1
  16. package/lib/api/search.js.map +1 -1
  17. package/lib/api/signals.js.map +1 -1
  18. package/lib/api/tokens.js.map +1 -1
  19. package/lib/api/tools.js.map +1 -1
  20. package/lib/api/transactions.js.map +1 -1
  21. package/lib/api/types.js.map +1 -1
  22. package/lib/api/uploadContext.js.map +1 -1
  23. package/lib/api/walletAuth.d.ts +1 -1
  24. package/lib/api/walletAuth.js.map +1 -1
  25. package/lib/auth/index.js.map +1 -1
  26. package/lib/auth/oauth.js.map +1 -1
  27. package/lib/auth/siwx.js.map +1 -1
  28. package/lib/index.js.map +1 -1
  29. package/lib/orders/attribution.js.map +1 -1
  30. package/lib/orders/erc20Fulfillment.js.map +1 -1
  31. package/lib/orders/orderUseCase.js.map +1 -1
  32. package/lib/orders/privateListings.js.map +1 -1
  33. package/lib/orders/types.js.map +1 -1
  34. package/lib/orders/utils.js.map +1 -1
  35. package/lib/provider/ethers-adapter.js.map +1 -1
  36. package/lib/provider/seaport-bridge.js.map +1 -1
  37. package/lib/provider/viem-adapter.js.map +1 -1
  38. package/lib/scopes.js.map +1 -1
  39. package/lib/sdk/assets.js +50 -7
  40. package/lib/sdk/assets.js.map +1 -1
  41. package/lib/sdk/base.js.map +1 -1
  42. package/lib/sdk/cancellation.js.map +1 -1
  43. package/lib/sdk/fulfillment.js.map +1 -1
  44. package/lib/sdk/orders.js.map +1 -1
  45. package/lib/sdk/tokens.js.map +1 -1
  46. package/lib/sdk.js.map +1 -1
  47. package/lib/stream/client.js.map +1 -1
  48. package/lib/stream/helpers.js.map +1 -1
  49. package/lib/stream/transport/phoenix.js.map +1 -1
  50. package/lib/stream/types.js.map +1 -1
  51. package/lib/types.js.map +1 -1
  52. package/lib/utils/address.js.map +1 -1
  53. package/lib/utils/case.js.map +1 -1
  54. package/lib/utils/chain.d.ts +1 -1
  55. package/lib/utils/chain.js.map +1 -1
  56. package/lib/utils/dateHelper.js.map +1 -1
  57. package/lib/utils/eip712.js.map +1 -1
  58. package/lib/utils/fees.js.map +1 -1
  59. package/lib/utils/fetchTransport.js.map +1 -1
  60. package/lib/utils/protocol.js.map +1 -1
  61. package/lib/utils/rateLimit.js.map +1 -1
  62. package/lib/utils/stringHelper.js.map +1 -1
  63. package/lib/utils/units.js.map +1 -1
  64. package/lib/utils/utils.js.map +1 -1
  65. package/lib/viem.js.map +1 -1
  66. package/package.json +3 -4
  67. package/src/abi/abis.ts +11 -4
  68. package/src/sdk/assets.ts +69 -13
package/src/sdk/assets.ts CHANGED
@@ -16,6 +16,47 @@ import {
16
16
  import { getDefaultConduit } from "../utils/utils"
17
17
  import type { SDKContext } from "./context"
18
18
 
19
+ type TransferHelperItem = {
20
+ itemType: number
21
+ token: string
22
+ identifier: string
23
+ amount: string
24
+ }
25
+
26
+ /**
27
+ * Combines entries for the same ERC20 (compared case-insensitively) into one
28
+ * entry with the summed amount, keeping first-seen order. The conduit pulls the
29
+ * total, so an allowance check per entry passes two transfers of 60 against an
30
+ * allowance of 100 that then revert onchain.
31
+ */
32
+ function mergeErc20Amounts<
33
+ T extends { asset: AssetWithTokenStandard; amount?: Amount },
34
+ >(entries: T[]): T[] {
35
+ const merged: T[] = []
36
+ const erc20Index = new Map<string, number>()
37
+ for (const entry of entries) {
38
+ if (entry.asset.tokenStandard !== TokenStandard.ERC20 || !entry.amount) {
39
+ merged.push(entry)
40
+ continue
41
+ }
42
+ const key = entry.asset.tokenAddress.toLowerCase()
43
+ const index = erc20Index.get(key)
44
+ if (index === undefined) {
45
+ erc20Index.set(key, merged.length)
46
+ merged.push(entry)
47
+ continue
48
+ }
49
+ const existing = merged[index]
50
+ merged[index] = {
51
+ ...existing,
52
+ amount: (
53
+ BigInt(String(existing.amount)) + BigInt(String(entry.amount))
54
+ ).toString(),
55
+ }
56
+ }
57
+ return merged
58
+ }
59
+
19
60
  /**
20
61
  * Asset transfer and approval operations
21
62
  */
@@ -206,15 +247,17 @@ export class AssetsManager {
206
247
  throw new Error("At least one asset must be provided")
207
248
  }
208
249
 
209
- // Validate asset data and build transfer items array for TransferHelper
210
- // This validation happens before any blockchain calls to ensure proper error messages
211
- const transferItems: Array<{
212
- itemType: number
213
- token: string
214
- identifier: string
215
- amount: string
216
- recipient: string
217
- }> = []
250
+ // Validate asset data and group transfer items per recipient, the shape
251
+ // TransferHelper.bulkTransfer takes. This validation happens before any
252
+ // blockchain calls to ensure proper error messages.
253
+ const itemsByRecipient = new Map<
254
+ string,
255
+ {
256
+ items: TransferHelperItem[]
257
+ recipient: string
258
+ validateERC721Receiver: boolean
259
+ }
260
+ >()
218
261
 
219
262
  for (const { asset, toAddress, amount } of assets) {
220
263
  let itemType: number
@@ -258,14 +301,27 @@ export class AssetsManager {
258
301
  )
259
302
  }
260
303
 
261
- transferItems.push({
304
+ const recipientKey = toAddress.toLowerCase()
305
+ let group = itemsByRecipient.get(recipientKey)
306
+ if (!group) {
307
+ // false matches transfer(), which sends ERC721s with transferFrom.
308
+ // true would also call onERC721Received on any recipient with code,
309
+ // including EIP-7702 delegated EOAs whose delegate lacks the hook.
310
+ group = {
311
+ items: [],
312
+ recipient: toAddress,
313
+ validateERC721Receiver: false,
314
+ }
315
+ itemsByRecipient.set(recipientKey, group)
316
+ }
317
+ group.items.push({
262
318
  itemType,
263
319
  token: asset.tokenAddress,
264
320
  identifier,
265
321
  amount: transferAmount,
266
- recipient: toAddress,
267
322
  })
268
323
  }
324
+ const transferItems = [...itemsByRecipient.values()]
269
325
 
270
326
  // Check account availability after parameter validation
271
327
  await this.context.requireAccountIsAvailable(fromAddress)
@@ -275,7 +331,7 @@ export class AssetsManager {
275
331
 
276
332
  // Check approvals for all assets before attempting transfer
277
333
  const unapprovedAssets: string[] = []
278
- for (const { asset, amount } of assets) {
334
+ for (const { asset, amount } of mergeErc20Amounts(assets)) {
279
335
  const isApproved = await this.checkAssetApproval(
280
336
  asset,
281
337
  fromAddress,
@@ -382,7 +438,7 @@ export class AssetsManager {
382
438
  const approvalsNeeded: Array<{ target: string; callData: string }> = []
383
439
  const processedContracts = new Set<string>()
384
440
 
385
- for (const { asset, amount } of assets) {
441
+ for (const { asset, amount } of mergeErc20Amounts(assets)) {
386
442
  const isApproved = await this.checkAssetApproval(
387
443
  asset,
388
444
  fromAddress,