@opensea/sdk 11.9.0 → 12.0.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.
@@ -1,9 +1,10 @@
1
- import type { BasicOrderParametersStruct } from "@opensea/seaport-js/lib/typechain-types/seaport/contracts/Seaport"
2
1
  import type {
3
- AdvancedOrder,
4
- OrderWithCounter,
5
- } from "@opensea/seaport-js/lib/types"
2
+ FulfillListingResponse as ApiFulfillListingResponse,
3
+ FulfillmentData as ApiFulfillmentData,
4
+ } from "@opensea/api-types"
5
+ import type { OrderWithCounter } from "@opensea/seaport-js/lib/types"
6
6
  import type { OpenSeaAccount, OrderSide } from "../types"
7
+ import type { Camelize } from "../utils/case"
7
8
 
8
9
  // Protocol data
9
10
  type OrderProtocolToProtocolData = {
@@ -68,46 +69,22 @@ export type OrderV2 = {
68
69
  remainingQuantity: number
69
70
  }
70
71
 
71
- export type FulfillmentDataResponse = {
72
- protocol: string
73
- fulfillmentData: FulfillmentData
74
- }
75
-
76
- type FulfillmentData = {
77
- transaction: Transaction
78
- orders: ProtocolData[]
79
- }
80
-
81
- type Transaction = {
82
- function: string
83
- chain: number
84
- to: string
85
- value: string
86
- inputData:
87
- | {
88
- // For fulfillAdvancedOrder
89
- advancedOrder: AdvancedOrder
90
- criteriaResolvers?: unknown[]
91
- fulfillerConduitKey?: string
92
- recipient: string
93
- }
94
- | {
95
- // For fulfillBasicOrder
96
- basicOrderParameters: BasicOrderParametersStruct
97
- }
98
- | {
99
- // For fulfillOrder
100
- order: OrderWithCounter
101
- fulfillerConduitKey?: string
102
- recipient: string
103
- }
104
- | {
105
- // Legacy: for backward compatibility
106
- orders:
107
- | OrderWithCounter[]
108
- | AdvancedOrder[]
109
- | BasicOrderParametersStruct[]
110
- }
72
+ /**
73
+ * Response from the fulfillment data endpoints. Camelized from
74
+ * `@opensea/api-types`, with `orders` narrowed to the seaport-js
75
+ * `ProtocolData` shape the SDK hands back to callers.
76
+ *
77
+ * The generated `transaction` carries `calldataSuffix`, the 4-byte attribution
78
+ * suffix {@link FulfillmentManager.fulfillOrder} appends to the calldata, and
79
+ * `inputData` covers all seven Seaport calls the API can return rather than the
80
+ * four the SDK used to declare.
81
+ */
82
+ export type FulfillmentDataResponse = Camelize<
83
+ Omit<ApiFulfillListingResponse, "fulfillment_data">
84
+ > & {
85
+ fulfillmentData: Camelize<Omit<ApiFulfillmentData, "orders">> & {
86
+ orders: ProtocolData[]
87
+ }
111
88
  }
112
89
 
113
90
  // API query types
package/src/scopes.ts CHANGED
@@ -14,6 +14,7 @@ export const OPENSEA_SCOPES = {
14
14
  READ_FAVORITES: "read:favorites",
15
15
  READ_SOCIAL: "read:social",
16
16
  READ_TOOLS: "read:tools",
17
+ READ_WALLETS: "read:wallets",
17
18
  WRITE_FAVORITES: "write:favorites",
18
19
  WRITE_SOCIAL: "write:social",
19
20
  WRITE_TOOLS: "write:tools",
@@ -3,6 +3,7 @@ import type { OrderComponents } from "@opensea/seaport-js/lib/types"
3
3
  import { CONDUIT_CONTROLLER_ABI, ERC20_ABI } from "../abi/abis"
4
4
  import type { Listing, Offer, Order } from "../api/types"
5
5
  import { CONDUIT_CONTROLLER_ADDRESS } from "../constants"
6
+ import { appendCalldataSuffix } from "../orders/attribution"
6
7
  import {
7
8
  getErc20Payment,
8
9
  getFulfillerConduitKey,
@@ -216,9 +217,9 @@ export class FulfillmentManager {
216
217
  } else if (
217
218
  (functionName === "fulfillBasicOrder" ||
218
219
  rawFunctionName === FULFILL_BASIC_ORDER_ALIAS) &&
219
- "basicOrderParameters" in inputData
220
+ "parameters" in inputData
220
221
  ) {
221
- params = [inputData.basicOrderParameters]
222
+ params = [inputData.parameters]
222
223
  } else if (functionName === "fulfillOrder" && "order" in inputData) {
223
224
  params = [
224
225
  inputData.order,
@@ -243,6 +244,10 @@ export class FulfillmentManager {
243
244
  args: params,
244
245
  })
245
246
 
247
+ // Re-encoding from inputData drops the attribution suffix the API appended
248
+ // to its own calldata, so put it back. See appendCalldataSuffix.
249
+ const data = appendCalldataSuffix(encodedData, transaction.calldataSuffix)
250
+
246
251
  // Send the transaction using the signer from wallet
247
252
  const wallet = this.context.wallet
248
253
  if (!("signer" in wallet)) {
@@ -251,7 +256,7 @@ export class FulfillmentManager {
251
256
  const tx = await wallet.signer.sendTransaction({
252
257
  to: transaction.to,
253
258
  value: BigInt(transaction.value),
254
- data: encodedData,
259
+ data,
255
260
  overrides: overrides as Record<string, unknown>,
256
261
  })
257
262
 
@@ -76,22 +76,41 @@ export class OpenSeaStreamClient {
76
76
  this.transport.onError(onError ?? (error => this.error(error)))
77
77
  }
78
78
 
79
- private debug(message: unknown) {
80
- if (this.logLevel <= LogLevel.DEBUG) {
81
- console.debug("[DEBUG]:", message)
79
+ private log(level: LogLevel, message: unknown) {
80
+ if (this.logLevel > level) {
81
+ return
82
+ }
83
+
84
+ switch (level) {
85
+ case LogLevel.DEBUG:
86
+ console.debug("[DEBUG]:", message)
87
+ break
88
+ case LogLevel.INFO:
89
+ console.info("[INFO]:", message)
90
+ break
91
+ case LogLevel.WARN:
92
+ console.warn("[WARN]:", message)
93
+ break
94
+ case LogLevel.ERROR:
95
+ console.error("[ERROR]:", message)
96
+ break
82
97
  }
83
98
  }
84
99
 
100
+ private debug(message: unknown) {
101
+ this.log(LogLevel.DEBUG, message)
102
+ }
103
+
85
104
  private info(message: unknown) {
86
- if (this.logLevel <= LogLevel.INFO) {
87
- console.info("[INFO]:", message)
88
- }
105
+ this.log(LogLevel.INFO, message)
106
+ }
107
+
108
+ private warn(message: unknown) {
109
+ this.log(LogLevel.WARN, message)
89
110
  }
90
111
 
91
112
  private error(message: unknown) {
92
- if (this.logLevel <= LogLevel.ERROR) {
93
- console.error("[ERROR]:", message)
94
- }
113
+ this.log(LogLevel.ERROR, message)
95
114
  }
96
115
 
97
116
  public connect = () => {
@@ -149,7 +168,6 @@ export class OpenSeaStreamClient {
149
168
  collectionSlug: string,
150
169
  callback: Callback<ItemMetadataUpdate>,
151
170
  ) => {
152
- this.debug(`Listening for item metadata updates on "${collectionSlug}"`)
153
171
  return this.on(EventType.ITEM_METADATA_UPDATED, collectionSlug, callback)
154
172
  }
155
173
 
@@ -157,7 +175,6 @@ export class OpenSeaStreamClient {
157
175
  collectionSlug: string,
158
176
  callback: Callback<ItemCancelledEvent>,
159
177
  ) => {
160
- this.debug(`Listening for item cancellations on "${collectionSlug}"`)
161
178
  return this.on(EventType.ITEM_CANCELLED, collectionSlug, callback)
162
179
  }
163
180
 
@@ -165,7 +182,6 @@ export class OpenSeaStreamClient {
165
182
  collectionSlug: string,
166
183
  callback: Callback<ItemListedEvent>,
167
184
  ) => {
168
- this.debug(`Listening for item listings on "${collectionSlug}"`)
169
185
  return this.on(EventType.ITEM_LISTED, collectionSlug, callback)
170
186
  }
171
187
 
@@ -173,7 +189,6 @@ export class OpenSeaStreamClient {
173
189
  collectionSlug: string,
174
190
  callback: Callback<ItemSoldEvent>,
175
191
  ) => {
176
- this.debug(`Listening for item sales on "${collectionSlug}"`)
177
192
  return this.on(EventType.ITEM_SOLD, collectionSlug, callback)
178
193
  }
179
194
 
@@ -181,23 +196,34 @@ export class OpenSeaStreamClient {
181
196
  collectionSlug: string,
182
197
  callback: Callback<ItemTransferredEvent>,
183
198
  ) => {
184
- this.debug(`Listening for item transfers on "${collectionSlug}"`)
185
199
  return this.on(EventType.ITEM_TRANSFERRED, collectionSlug, callback)
186
200
  }
187
201
 
202
+ /**
203
+ * No-op. The Stream API does not emit `item_received_offer` and never has, so
204
+ * this only ever registered a handler that could not fire. Item-level offers
205
+ * arrive as `item_received_bid`, so use {@link onItemReceivedBid} instead.
206
+ *
207
+ * Kept callable, and kept from opening a connection for a topic that yields
208
+ * nothing, so existing call sites keep compiling and running unchanged.
209
+ *
210
+ * @deprecated Use {@link onItemReceivedBid}. This does nothing.
211
+ * @hidden
212
+ */
188
213
  public onItemReceivedOffer = (
189
- collectionSlug: string,
190
- callback: Callback<ItemReceivedOfferEvent>,
214
+ _collectionSlug: string,
215
+ _callback: Callback<ItemReceivedOfferEvent>,
191
216
  ) => {
192
- this.debug(`Listening for item offers on "${collectionSlug}"`)
193
- return this.on(EventType.ITEM_RECEIVED_OFFER, collectionSlug, callback)
217
+ this.warn(
218
+ "onItemReceivedOffer does nothing: the Stream API does not emit item_received_offer. Item-level offers arrive as item_received_bid, via onItemReceivedBid.",
219
+ )
220
+ return () => {}
194
221
  }
195
222
 
196
223
  public onItemReceivedBid = (
197
224
  collectionSlug: string,
198
225
  callback: Callback<ItemReceivedBidEvent>,
199
226
  ) => {
200
- this.debug(`Listening for item bids on "${collectionSlug}"`)
201
227
  return this.on(EventType.ITEM_RECEIVED_BID, collectionSlug, callback)
202
228
  }
203
229
 
@@ -205,7 +231,6 @@ export class OpenSeaStreamClient {
205
231
  collectionSlug: string,
206
232
  callback: Callback<CollectionOfferEvent>,
207
233
  ) => {
208
- this.debug(`Listening for collection offers on "${collectionSlug}"`)
209
234
  return this.on(EventType.COLLECTION_OFFER, collectionSlug, callback)
210
235
  }
211
236
 
@@ -213,7 +238,6 @@ export class OpenSeaStreamClient {
213
238
  collectionSlug: string,
214
239
  callback: Callback<TraitOfferEvent>,
215
240
  ) => {
216
- this.debug(`Listening for trait offers on "${collectionSlug}"`)
217
241
  return this.on(EventType.TRAIT_OFFER, collectionSlug, callback)
218
242
  }
219
243
 
@@ -221,7 +245,6 @@ export class OpenSeaStreamClient {
221
245
  collectionSlug: string,
222
246
  callback: Callback<OrderValidationEvent>,
223
247
  ) => {
224
- this.debug(`Listening for order invalidation events on "${collectionSlug}"`)
225
248
  return this.on(EventType.ORDER_INVALIDATE, collectionSlug, callback)
226
249
  }
227
250
 
@@ -229,7 +252,6 @@ export class OpenSeaStreamClient {
229
252
  collectionSlug: string,
230
253
  callback: Callback<OrderValidationEvent>,
231
254
  ) => {
232
- this.debug(`Listening for order revalidation events on "${collectionSlug}"`)
233
255
  return this.on(EventType.ORDER_REVALIDATE, collectionSlug, callback)
234
256
  }
235
257
 
@@ -70,6 +70,13 @@ export enum EventType {
70
70
  ITEM_LISTED = "item_listed",
71
71
  ITEM_SOLD = "item_sold",
72
72
  ITEM_TRANSFERRED = "item_transferred",
73
+ /**
74
+ * Never emitted by the Stream API. Item-level offers arrive as
75
+ * {@link EventType.ITEM_RECEIVED_BID}. Kept so existing references compile.
76
+ *
77
+ * @deprecated Use {@link EventType.ITEM_RECEIVED_BID}.
78
+ * @hidden
79
+ */
73
80
  ITEM_RECEIVED_OFFER = "item_received_offer",
74
81
  ITEM_RECEIVED_BID = "item_received_bid",
75
82
  ITEM_CANCELLED = "item_cancelled",
@@ -153,20 +160,28 @@ export type CollectionIdentifier = {
153
160
  slug: string
154
161
  }
155
162
 
156
- export interface ItemListedEventPayload extends Payload {
163
+ // Shared fields for order events with maker, taker, payment, and timestamps.
164
+ interface BaseOrderEventPayload extends Payload {
157
165
  quantity: number
158
- listing_type: string
159
- listing_date: string
160
- expiration_date: string
161
166
  maker: Account
162
167
  taker: Account
163
- base_price: string
164
- payment_token: PaymentToken
165
- is_private: boolean
166
168
  order_hash: string
169
+ payment_token: PaymentToken
167
170
  event_timestamp: string
168
171
  }
169
172
 
173
+ // Shared price and expiry fields for priced order events.
174
+ interface BasePricedOrderEventPayload extends BaseOrderEventPayload {
175
+ base_price: string
176
+ expiration_date: string
177
+ }
178
+
179
+ export interface ItemListedEventPayload extends BasePricedOrderEventPayload {
180
+ listing_type: string
181
+ listing_date: string
182
+ is_private: boolean
183
+ }
184
+
170
185
  export type ItemListedEvent = BaseStreamMessage<ItemListedEventPayload>
171
186
 
172
187
  export type Transaction = {
@@ -174,18 +189,12 @@ export type Transaction = {
174
189
  timestamp: string
175
190
  }
176
191
 
177
- export interface ItemSoldEventPayload extends Payload {
178
- quantity: number
192
+ export interface ItemSoldEventPayload extends BaseOrderEventPayload {
179
193
  listing_type: string
180
194
  closing_date: string
181
195
  transaction: Transaction
182
- maker: Account
183
- taker: Account
184
- order_hash: string
185
196
  sale_price: string
186
- payment_token: PaymentToken
187
197
  is_private: boolean
188
- event_timestamp: string
189
198
  }
190
199
 
191
200
  export type ItemSoldEvent = BaseStreamMessage<ItemSoldEventPayload>
@@ -201,65 +210,42 @@ export interface ItemTransferredEventPayload extends Payload {
201
210
  export type ItemTransferredEvent =
202
211
  BaseStreamMessage<ItemTransferredEventPayload>
203
212
 
204
- export interface ItemReceivedBidEventPayload extends Payload {
205
- quantity: number
213
+ export interface ItemReceivedBidEventPayload
214
+ extends BasePricedOrderEventPayload {
206
215
  created_date: string
207
- expiration_date: string
208
- maker: Account
209
- taker: Account
210
- order_hash: string
211
- base_price: string
212
- payment_token: PaymentToken
213
- event_timestamp: string
214
216
  }
215
217
 
216
218
  export type ItemReceivedBidEvent =
217
219
  BaseStreamMessage<ItemReceivedBidEventPayload>
218
220
 
219
- export interface ItemReceivedOfferEventPayload extends Payload {
220
- quantity: number
221
- created_date: string
222
- expiration_date: string
223
- maker: Account
224
- taker: Account
225
- order_hash: string
226
- base_price: string
227
- payment_token: PaymentToken
228
- event_timestamp: string
229
- }
221
+ /**
222
+ * @deprecated Never emitted. Use {@link ItemReceivedBidEventPayload}.
223
+ * @hidden
224
+ */
225
+ export interface ItemReceivedOfferEventPayload
226
+ extends ItemReceivedBidEventPayload {}
230
227
 
228
+ /**
229
+ * @deprecated Never emitted. Use {@link ItemReceivedBidEvent}.
230
+ * @hidden
231
+ */
231
232
  export type ItemReceivedOfferEvent =
232
233
  BaseStreamMessage<ItemReceivedOfferEventPayload>
233
234
 
234
- export interface ItemCancelledEventPayload extends Payload {
235
- quantity: number
236
- base_price: string
237
- expiration_date: string
238
- maker: Account
239
- taker: Account
235
+ export interface ItemCancelledEventPayload extends BasePricedOrderEventPayload {
240
236
  listing_type: string
241
237
  listing_date: string
242
238
  transaction: Transaction
243
- payment_token: PaymentToken
244
- order_hash: string
245
239
  is_private: boolean
246
- event_timestamp: string
247
240
  }
248
241
 
249
242
  export type ItemCancelledEvent = BaseStreamMessage<ItemCancelledEventPayload>
250
243
 
251
- export interface CollectionOfferEventPayload extends Payload {
252
- quantity: number
244
+ export interface CollectionOfferEventPayload
245
+ extends BasePricedOrderEventPayload {
253
246
  created_date: string
254
- expiration_date: string
255
- maker: Account
256
- taker: Account
257
- base_price: string
258
- order_hash: string
259
- payment_token: PaymentToken
260
247
  collection_criteria: CollectionIdentifier
261
248
  asset_contract_criteria: AssetContractCriteria
262
- event_timestamp: string
263
249
  }
264
250
 
265
251
  export type CollectionOfferEvent =
@@ -270,20 +256,9 @@ export type TraitCriteria = {
270
256
  trait_name: string
271
257
  }
272
258
 
273
- export interface TraitOfferEventPayload extends Payload {
274
- quantity: number
275
- created_date: string
276
- expiration_date: string
277
- maker: Account
278
- taker: Account
279
- base_price: string
280
- order_hash: string
281
- payment_token: PaymentToken
282
- collection_criteria: CollectionIdentifier
283
- asset_contract_criteria: AssetContractCriteria
259
+ export interface TraitOfferEventPayload extends CollectionOfferEventPayload {
284
260
  trait_criteria?: TraitCriteria
285
261
  trait_criteria_list?: TraitCriteria[]
286
- event_timestamp: string
287
262
  }
288
263
 
289
264
  export type TraitOfferEvent = BaseStreamMessage<TraitOfferEventPayload>