@opensea/sdk 11.9.0 → 12.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.
- package/README.md +5 -2
- package/lib/api/types.d.ts +20 -64
- package/lib/api/types.js.map +1 -1
- package/lib/api/walletAuth.d.ts +95 -8
- package/lib/api/walletAuth.js +75 -6
- package/lib/api/walletAuth.js.map +1 -1
- package/lib/orders/attribution.d.ts +18 -0
- package/lib/orders/attribution.js +29 -0
- package/lib/orders/attribution.js.map +1 -0
- package/lib/orders/erc20Fulfillment.js +67 -4
- package/lib/orders/erc20Fulfillment.js.map +1 -1
- package/lib/orders/types.d.ts +16 -28
- package/lib/orders/types.js.map +1 -1
- package/lib/provider/seaport-bridge.js +2 -2
- package/lib/provider/seaport-bridge.js.map +1 -1
- package/lib/provider/viem-adapter.js +3 -3
- package/lib/provider/viem-adapter.js.map +1 -1
- package/lib/scopes.d.ts +1 -0
- package/lib/scopes.js +1 -0
- package/lib/scopes.js.map +1 -1
- package/lib/sdk/assets.js +8 -0
- package/lib/sdk/assets.js.map +1 -1
- package/lib/sdk/cancellation.js +6 -1
- package/lib/sdk/cancellation.js.map +1 -1
- package/lib/sdk/fulfillment.js +7 -3
- package/lib/sdk/fulfillment.js.map +1 -1
- package/lib/stream/client.d.ts +14 -1
- package/lib/stream/client.js +39 -22
- package/lib/stream/client.js.map +1 -1
- package/lib/stream/types.d.ts +32 -63
- package/lib/stream/types.js +7 -0
- package/lib/stream/types.js.map +1 -1
- package/lib/utils/eip712.d.ts +21 -0
- package/lib/utils/eip712.js +54 -0
- package/lib/utils/eip712.js.map +1 -0
- package/package.json +2 -2
- package/src/api/types.ts +27 -64
- package/src/api/walletAuth.ts +100 -13
- package/src/orders/attribution.ts +29 -0
- package/src/orders/erc20Fulfillment.ts +74 -4
- package/src/orders/types.ts +21 -44
- package/src/provider/seaport-bridge.ts +2 -3
- package/src/provider/viem-adapter.ts +3 -4
- package/src/scopes.ts +1 -0
- package/src/sdk/assets.ts +9 -0
- package/src/sdk/cancellation.ts +6 -1
- package/src/sdk/fulfillment.ts +8 -3
- package/src/stream/client.ts +45 -23
- package/src/stream/types.ts +39 -64
- package/src/utils/eip712.ts +57 -0
|
@@ -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
|
-
|
|
175
|
-
|
|
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
|
-
|
|
204
|
-
|
|
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
|
}
|
package/src/orders/types.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { BasicOrderParametersStruct } from "@opensea/seaport-js/lib/typechain-types/seaport/contracts/Seaport"
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "@opensea/
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
type
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
@@ -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/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",
|
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,
|
package/src/sdk/cancellation.ts
CHANGED
|
@@ -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
|
-
|
|
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) {
|
package/src/sdk/fulfillment.ts
CHANGED
|
@@ -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
|
-
"
|
|
220
|
+
"parameters" in inputData
|
|
220
221
|
) {
|
|
221
|
-
params = [inputData.
|
|
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
|
|
259
|
+
data,
|
|
255
260
|
overrides: overrides as Record<string, unknown>,
|
|
256
261
|
})
|
|
257
262
|
|
package/src/stream/client.ts
CHANGED
|
@@ -76,22 +76,41 @@ export class OpenSeaStreamClient {
|
|
|
76
76
|
this.transport.onError(onError ?? (error => this.error(error)))
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
private
|
|
80
|
-
if (this.logLevel
|
|
81
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
190
|
-
|
|
214
|
+
_collectionSlug: string,
|
|
215
|
+
_callback: Callback<ItemReceivedOfferEvent>,
|
|
191
216
|
) => {
|
|
192
|
-
this.
|
|
193
|
-
|
|
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
|
|
package/src/stream/types.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
205
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
|
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
|
|
252
|
-
|
|
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
|
|
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>
|