@opensea/sdk 12.5.0 → 12.7.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.
- package/README.md +53 -0
- package/lib/api/api.d.ts +19 -3
- package/lib/api/api.js +24 -13
- package/lib/api/api.js.map +1 -1
- package/lib/api/nfts.d.ts +7 -2
- package/lib/api/nfts.js +10 -1
- package/lib/api/nfts.js.map +1 -1
- package/lib/api/types.d.ts +37 -1
- package/lib/api/types.js.map +1 -1
- package/lib/auth/index.d.ts +2 -0
- package/lib/auth/index.js +13 -10
- package/lib/auth/index.js.map +1 -1
- package/lib/auth/oauth-types.d.ts +10 -0
- package/lib/auth/oauth.d.ts +16 -0
- package/lib/auth/oauth.js +61 -22
- package/lib/auth/oauth.js.map +1 -1
- package/lib/auth/siwx.d.ts +17 -1
- package/lib/auth/siwx.js +10 -4
- package/lib/auth/siwx.js.map +1 -1
- package/lib/auth/types.d.ts +11 -0
- package/lib/sdk/base.d.ts +9 -2
- package/lib/sdk/base.js +7 -2
- package/lib/sdk/base.js.map +1 -1
- package/lib/sdk/orders.d.ts +27 -3
- package/lib/sdk/orders.js +142 -176
- package/lib/sdk/orders.js.map +1 -1
- package/lib/types.d.ts +8 -3
- package/lib/types.js.map +1 -1
- package/lib/utils/case.d.ts +22 -0
- package/lib/utils/fetchTransport.d.ts +29 -0
- package/lib/utils/fetchTransport.js +26 -0
- package/lib/utils/fetchTransport.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +7 -0
- package/lib/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/src/api/api.ts +36 -18
- package/src/api/nfts.ts +11 -0
- package/src/api/types.ts +43 -0
- package/src/auth/index.ts +45 -26
- package/src/auth/oauth-types.ts +11 -0
- package/src/auth/oauth.ts +70 -26
- package/src/auth/siwx.ts +30 -10
- package/src/auth/types.ts +12 -0
- package/src/sdk/base.ts +8 -1
- package/src/sdk/orders.ts +196 -226
- package/src/types.ts +9 -3
- package/src/utils/case.ts +22 -0
- package/src/utils/fetchTransport.ts +36 -0
- package/src/utils/index.ts +7 -0
package/src/auth/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FetchImpl } from "../utils/fetchTransport"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A scoped JWT token returned by the auth server.
|
|
3
5
|
*/
|
|
@@ -28,6 +30,16 @@ export interface OpenSeaAuthConfig {
|
|
|
28
30
|
apiBaseUrl?: string
|
|
29
31
|
/** @deprecated Use `apiBaseUrl`. */
|
|
30
32
|
authBaseUrl?: string
|
|
33
|
+
/**
|
|
34
|
+
* Transport used for every request this instance makes, defaulting to the global `fetch`.
|
|
35
|
+
* Same seam as {@link OpenSeaAPIConfig.fetch}, so one wrapper can cover the auth flow and the
|
|
36
|
+
* API client.
|
|
37
|
+
*
|
|
38
|
+
* It sees the session cookie, the scoped token and the exchanged JWT, so anything it logs or
|
|
39
|
+
* caches is a credential. Nothing here is a cacheable representation: every call either
|
|
40
|
+
* mints, exchanges or revokes a token.
|
|
41
|
+
*/
|
|
42
|
+
fetch?: FetchImpl
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
/**
|
package/src/sdk/base.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
AssetWithTokenStandard,
|
|
20
20
|
Chain,
|
|
21
21
|
EventData,
|
|
22
|
+
FetchImpl,
|
|
22
23
|
} from "../types"
|
|
23
24
|
import { EventType, OrderSide } from "../types"
|
|
24
25
|
import { checksumAddress } from "../utils/address"
|
|
@@ -120,11 +121,17 @@ export class BaseOpenSeaSDK {
|
|
|
120
121
|
* ```
|
|
121
122
|
*
|
|
122
123
|
* @param apiBaseUrl Optional base URL override (defaults to mainnet).
|
|
124
|
+
* @param options Optional `fetch` transport, forwarded to
|
|
125
|
+
* {@link OpenSeaAPI.requestInstantApiKey}. This is a static method with no
|
|
126
|
+
* instance whose configured transport it could read, so a consumer that routes
|
|
127
|
+
* every request through its own transport passes it here. Defaults to the
|
|
128
|
+
* global `fetch`.
|
|
123
129
|
*/
|
|
124
130
|
public static async requestInstantApiKey(
|
|
125
131
|
apiBaseUrl?: string,
|
|
132
|
+
options: { fetch?: FetchImpl } = {},
|
|
126
133
|
): Promise<RequestInstantApiKeyResponse> {
|
|
127
|
-
return OpenSeaAPI.requestInstantApiKey(apiBaseUrl)
|
|
134
|
+
return OpenSeaAPI.requestInstantApiKey(apiBaseUrl, options)
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
// ─── Event Listeners ───────────────────────────────────────────────
|
package/src/sdk/orders.ts
CHANGED
|
@@ -43,13 +43,31 @@ export interface BulkOrderResult<T extends Listing | Offer = Listing | Offer> {
|
|
|
43
43
|
failed: Array<{
|
|
44
44
|
/** Index of the failed order in the original input array */
|
|
45
45
|
index: number
|
|
46
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* The signed order that failed to submit. When a bulk call received a
|
|
48
|
+
* single order and creating it threw, there is nothing signed to report
|
|
49
|
+
* and this is an empty object rather than a real order, so check for the
|
|
50
|
+
* seaport fields before reading them.
|
|
51
|
+
*/
|
|
47
52
|
order?: ProtocolData
|
|
48
53
|
/** The error that occurred during submission */
|
|
49
54
|
error: Error
|
|
50
55
|
}>
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Normalizes a caller-supplied salt for seaport-js.
|
|
60
|
+
*
|
|
61
|
+
* seaport-js only generates a salt when the field is `undefined`, and that
|
|
62
|
+
* generated salt carries the domain tag (the first four bytes of
|
|
63
|
+
* `keccak256(domain)`) used for onchain attribution. Any defined value,
|
|
64
|
+
* including `0`, suppresses both. So an omitted salt has to stay omitted all
|
|
65
|
+
* the way through, and an explicit `0` has to survive as `"0"`.
|
|
66
|
+
*/
|
|
67
|
+
function normalizeSalt(salt: Amount | undefined): string | undefined {
|
|
68
|
+
return salt !== undefined ? BigInt(salt).toString() : undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
53
71
|
/**
|
|
54
72
|
* Manager for order building and creation operations.
|
|
55
73
|
* Handles listing creation, offer creation, and collection offers.
|
|
@@ -141,6 +159,112 @@ export class OrdersManager {
|
|
|
141
159
|
return considerationItems
|
|
142
160
|
}
|
|
143
161
|
|
|
162
|
+
/**
|
|
163
|
+
* The single-order path a bulk call takes when it receives exactly one
|
|
164
|
+
* order. A bulk signature costs more to decode onchain because of the merkle
|
|
165
|
+
* proof, so one order goes through the normal single-order signature.
|
|
166
|
+
*/
|
|
167
|
+
private async createOneForBulk<T extends Listing | Offer>(
|
|
168
|
+
create: () => Promise<T>,
|
|
169
|
+
continueOnError: boolean,
|
|
170
|
+
): Promise<BulkOrderResult<T>> {
|
|
171
|
+
try {
|
|
172
|
+
const order = await create()
|
|
173
|
+
return {
|
|
174
|
+
successful: [order],
|
|
175
|
+
failed: [],
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (continueOnError) {
|
|
179
|
+
return {
|
|
180
|
+
successful: [],
|
|
181
|
+
failed: [
|
|
182
|
+
{
|
|
183
|
+
index: 0,
|
|
184
|
+
order: {} as ProtocolData, // Order wasn't created
|
|
185
|
+
error: error as Error,
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
throw error
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Submits bulk-signed orders to the OpenSea API one at a time and collects
|
|
196
|
+
* the outcome. Rate limiting is handled by the API client.
|
|
197
|
+
*
|
|
198
|
+
* Shared by createBulkListings and createBulkOffers so that submission
|
|
199
|
+
* ordering, continueOnError and progress reporting cannot drift apart
|
|
200
|
+
* between the two.
|
|
201
|
+
*/
|
|
202
|
+
private async submitBulkSignedOrders<T extends Listing | Offer>({
|
|
203
|
+
orders,
|
|
204
|
+
noun,
|
|
205
|
+
post,
|
|
206
|
+
continueOnError,
|
|
207
|
+
onProgress,
|
|
208
|
+
}: {
|
|
209
|
+
orders: ProtocolData[]
|
|
210
|
+
noun: string
|
|
211
|
+
post: (order: ProtocolData) => Promise<T>
|
|
212
|
+
continueOnError: boolean
|
|
213
|
+
onProgress?: (completed: number, total: number) => void
|
|
214
|
+
}): Promise<BulkOrderResult<T>> {
|
|
215
|
+
this.context.logger(
|
|
216
|
+
`Starting submission of ${orders.length} bulk-signed ${pluralize(orders.length, noun)} to OpenSea API...`,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
const submittedOrders: T[] = []
|
|
220
|
+
const failedOrders: BulkOrderResult["failed"] = []
|
|
221
|
+
|
|
222
|
+
for (let i = 0; i < orders.length; i++) {
|
|
223
|
+
this.context.logger(`Submitting ${noun} ${i + 1}/${orders.length}...`)
|
|
224
|
+
try {
|
|
225
|
+
const submittedOrder = await post(orders[i])
|
|
226
|
+
submittedOrders.push(submittedOrder)
|
|
227
|
+
this.context.logger(`Completed ${noun} ${i + 1}/${orders.length}`)
|
|
228
|
+
} catch (error) {
|
|
229
|
+
const errorMessage = (error as Error).message
|
|
230
|
+
this.context.logger(
|
|
231
|
+
`Failed ${noun} ${i + 1}/${orders.length}: ${errorMessage}`,
|
|
232
|
+
)
|
|
233
|
+
failedOrders.push({
|
|
234
|
+
index: i,
|
|
235
|
+
order: orders[i],
|
|
236
|
+
error: error as Error,
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
// If not continuing on error, throw immediately
|
|
240
|
+
if (!continueOnError) {
|
|
241
|
+
throw error
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Reached for each order that finished, submitted or failed. A failure
|
|
246
|
+
// with continueOnError false throws above and is never reported here.
|
|
247
|
+
onProgress?.(i + 1, orders.length)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (submittedOrders.length > 0) {
|
|
251
|
+
this.context.logger(
|
|
252
|
+
`Successfully submitted ${submittedOrders.length}/${orders.length} ${pluralize(submittedOrders.length, noun)}`,
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (failedOrders.length > 0) {
|
|
257
|
+
this.context.logger(
|
|
258
|
+
`Failed to submit ${failedOrders.length}/${orders.length} ${pluralize(failedOrders.length, noun)}`,
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
successful: submittedOrders,
|
|
264
|
+
failed: failedOrders,
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
144
268
|
/**
|
|
145
269
|
* Build listing order without submitting to API
|
|
146
270
|
* @param options Listing parameters
|
|
@@ -225,7 +349,7 @@ export class OrdersManager {
|
|
|
225
349
|
expirationTime?.toString() ?? oneMonthFromNowInSeconds().toString(),
|
|
226
350
|
zone,
|
|
227
351
|
domain,
|
|
228
|
-
salt:
|
|
352
|
+
salt: normalizeSalt(salt),
|
|
229
353
|
restrictedByZone: zone !== ZERO_ADDRESS,
|
|
230
354
|
allowPartialFills: true,
|
|
231
355
|
},
|
|
@@ -356,7 +480,7 @@ export class OrdersManager {
|
|
|
356
480
|
: oneMonthFromNowInSeconds().toString(),
|
|
357
481
|
zone,
|
|
358
482
|
domain,
|
|
359
|
-
salt:
|
|
483
|
+
salt: normalizeSalt(salt),
|
|
360
484
|
restrictedByZone: zone !== ZERO_ADDRESS,
|
|
361
485
|
allowPartialFills: true,
|
|
362
486
|
},
|
|
@@ -539,7 +663,9 @@ export class OrdersManager {
|
|
|
539
663
|
* @param options.listings Array of listing parameters. Each listing requires asset, amount, and optionally other listing parameters.
|
|
540
664
|
* @param options.accountAddress Address of the wallet making the listings
|
|
541
665
|
* @param options.continueOnError If true, continue submitting remaining listings even if some fail. Default: false (throw on first error).
|
|
542
|
-
* @param options.onProgress Optional callback for progress updates. Called after each
|
|
666
|
+
* @param options.onProgress Optional callback for progress updates. Called after each
|
|
667
|
+
* listing that finishes, whether it succeeded or failed. A failure when `continueOnError`
|
|
668
|
+
* is false throws instead, so that listing is never reported.
|
|
543
669
|
* @returns {@link BulkOrderResult} containing successful orders and any failures.
|
|
544
670
|
*
|
|
545
671
|
* @throws Error if listings array is empty
|
|
@@ -575,30 +701,10 @@ export class OrdersManager {
|
|
|
575
701
|
|
|
576
702
|
// If only one listing, use normal signature to avoid bulk signature overhead
|
|
577
703
|
if (listings.length === 1) {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
})
|
|
583
|
-
return {
|
|
584
|
-
successful: [order],
|
|
585
|
-
failed: [],
|
|
586
|
-
}
|
|
587
|
-
} catch (error) {
|
|
588
|
-
if (continueOnError) {
|
|
589
|
-
return {
|
|
590
|
-
successful: [],
|
|
591
|
-
failed: [
|
|
592
|
-
{
|
|
593
|
-
index: 0,
|
|
594
|
-
order: {} as ProtocolData, // Order wasn't created
|
|
595
|
-
error: error as Error,
|
|
596
|
-
},
|
|
597
|
-
],
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
throw error
|
|
601
|
-
}
|
|
704
|
+
return this.createOneForBulk(
|
|
705
|
+
() => this.createListing({ ...listings[0], accountAddress }),
|
|
706
|
+
continueOnError,
|
|
707
|
+
)
|
|
602
708
|
}
|
|
603
709
|
|
|
604
710
|
await this.context.requireAccountIsAvailable(accountAddress)
|
|
@@ -608,6 +714,7 @@ export class OrdersManager {
|
|
|
608
714
|
nft: NFT
|
|
609
715
|
collection: OpenSeaCollection
|
|
610
716
|
paymentTokenAddress: string
|
|
717
|
+
basePrice: bigint
|
|
611
718
|
zone: string
|
|
612
719
|
domain?: string
|
|
613
720
|
salt?: Amount
|
|
@@ -620,13 +727,10 @@ export class OrdersManager {
|
|
|
620
727
|
const {
|
|
621
728
|
asset,
|
|
622
729
|
amount,
|
|
623
|
-
quantity = 1,
|
|
624
730
|
domain,
|
|
625
731
|
salt,
|
|
626
732
|
listingTime,
|
|
627
733
|
expirationTime,
|
|
628
|
-
buyerAddress,
|
|
629
|
-
includeOptionalCreatorFees = false,
|
|
630
734
|
zone = ZERO_ADDRESS,
|
|
631
735
|
} = listing
|
|
632
736
|
|
|
@@ -641,32 +745,14 @@ export class OrdersManager {
|
|
|
641
745
|
collection.pricingCurrencies?.listingCurrency?.address ??
|
|
642
746
|
getListingPaymentToken(this.context.chain)
|
|
643
747
|
|
|
644
|
-
|
|
645
|
-
|
|
748
|
+
// Priced here, in input order, so a bad amount throws on the first
|
|
749
|
+
// offending listing rather than out of the Promise.all below.
|
|
646
750
|
const { basePrice } = await this.getPriceParametersCallback(
|
|
647
751
|
OrderSide.LISTING,
|
|
648
752
|
paymentTokenAddress,
|
|
649
753
|
amount,
|
|
650
754
|
)
|
|
651
755
|
|
|
652
|
-
const considerationFeeItems = await this.getFees({
|
|
653
|
-
collection,
|
|
654
|
-
seller: accountAddress,
|
|
655
|
-
paymentTokenAddress,
|
|
656
|
-
amount: basePrice,
|
|
657
|
-
includeOptionalCreatorFees,
|
|
658
|
-
isPrivateListing: !!buyerAddress,
|
|
659
|
-
})
|
|
660
|
-
|
|
661
|
-
if (buyerAddress) {
|
|
662
|
-
const { getPrivateListingConsiderations } = await import(
|
|
663
|
-
"../orders/privateListings"
|
|
664
|
-
)
|
|
665
|
-
considerationFeeItems.push(
|
|
666
|
-
...getPrivateListingConsiderations(offerAssetItems, buyerAddress),
|
|
667
|
-
)
|
|
668
|
-
}
|
|
669
|
-
|
|
670
756
|
let finalZone = zone
|
|
671
757
|
if (collection.requiredZone) {
|
|
672
758
|
finalZone = collection.requiredZone
|
|
@@ -676,6 +762,7 @@ export class OrdersManager {
|
|
|
676
762
|
nft,
|
|
677
763
|
collection,
|
|
678
764
|
paymentTokenAddress,
|
|
765
|
+
basePrice,
|
|
679
766
|
zone: finalZone,
|
|
680
767
|
domain,
|
|
681
768
|
salt,
|
|
@@ -685,9 +772,8 @@ export class OrdersManager {
|
|
|
685
772
|
}
|
|
686
773
|
|
|
687
774
|
// Create the bulk orders using seaport's createBulkOrders method
|
|
688
|
-
const createOrderInputsForSeaport = listings.map((listing, index) => {
|
|
775
|
+
const createOrderInputsForSeaport = listings.map(async (listing, index) => {
|
|
689
776
|
const {
|
|
690
|
-
amount,
|
|
691
777
|
quantity = 1,
|
|
692
778
|
listingTime,
|
|
693
779
|
expirationTime,
|
|
@@ -701,44 +787,36 @@ export class OrdersManager {
|
|
|
701
787
|
[BigInt(quantity ?? 1)],
|
|
702
788
|
)
|
|
703
789
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
paymentTokenAddress: metadata.paymentTokenAddress,
|
|
713
|
-
amount: basePrice,
|
|
714
|
-
includeOptionalCreatorFees,
|
|
715
|
-
isPrivateListing: !!buyerAddress,
|
|
716
|
-
})
|
|
790
|
+
const considerationFeeItems = await this.getFees({
|
|
791
|
+
collection: metadata.collection,
|
|
792
|
+
seller: accountAddress,
|
|
793
|
+
paymentTokenAddress: metadata.paymentTokenAddress,
|
|
794
|
+
amount: metadata.basePrice,
|
|
795
|
+
includeOptionalCreatorFees,
|
|
796
|
+
isPrivateListing: !!buyerAddress,
|
|
797
|
+
})
|
|
717
798
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
799
|
+
if (buyerAddress) {
|
|
800
|
+
const { getPrivateListingConsiderations } = await import(
|
|
801
|
+
"../orders/privateListings"
|
|
802
|
+
)
|
|
803
|
+
considerationFeeItems.push(
|
|
804
|
+
...getPrivateListingConsiderations(offerAssetItems, buyerAddress),
|
|
805
|
+
)
|
|
806
|
+
}
|
|
726
807
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
allowPartialFills: true,
|
|
740
|
-
}
|
|
741
|
-
})
|
|
808
|
+
return {
|
|
809
|
+
offer: offerAssetItems,
|
|
810
|
+
consideration: considerationFeeItems,
|
|
811
|
+
startTime: listingTime?.toString(),
|
|
812
|
+
endTime:
|
|
813
|
+
expirationTime?.toString() ?? oneMonthFromNowInSeconds().toString(),
|
|
814
|
+
zone: metadata.zone,
|
|
815
|
+
domain: metadata.domain,
|
|
816
|
+
salt: normalizeSalt(metadata.salt),
|
|
817
|
+
restrictedByZone: metadata.zone !== ZERO_ADDRESS,
|
|
818
|
+
allowPartialFills: true,
|
|
819
|
+
}
|
|
742
820
|
})
|
|
743
821
|
|
|
744
822
|
const resolvedInputs = await Promise.all(createOrderInputsForSeaport)
|
|
@@ -750,61 +828,17 @@ export class OrdersManager {
|
|
|
750
828
|
|
|
751
829
|
const orders = await executeAllActions()
|
|
752
830
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
const submittedOrders: Listing[] = []
|
|
760
|
-
const failedOrders: BulkOrderResult["failed"] = []
|
|
761
|
-
|
|
762
|
-
for (let i = 0; i < orders.length; i++) {
|
|
763
|
-
this.context.logger(`Submitting listing ${i + 1}/${orders.length}...`)
|
|
764
|
-
try {
|
|
765
|
-
const submittedOrder = await this.context.api.postListing(
|
|
766
|
-
orders[i],
|
|
831
|
+
return this.submitBulkSignedOrders({
|
|
832
|
+
orders,
|
|
833
|
+
noun: "listing",
|
|
834
|
+
post: order =>
|
|
835
|
+
this.context.api.postListing(
|
|
836
|
+
order,
|
|
767
837
|
this.context.seaport.contract.target as string,
|
|
768
|
-
)
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const errorMessage = (error as Error).message
|
|
773
|
-
this.context.logger(
|
|
774
|
-
`Failed listing ${i + 1}/${orders.length}: ${errorMessage}`,
|
|
775
|
-
)
|
|
776
|
-
failedOrders.push({
|
|
777
|
-
index: i,
|
|
778
|
-
order: orders[i],
|
|
779
|
-
error: error as Error,
|
|
780
|
-
})
|
|
781
|
-
|
|
782
|
-
// If not continuing on error, throw immediately
|
|
783
|
-
if (!continueOnError) {
|
|
784
|
-
throw error
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
// Call progress callback after each listing (successful or failed)
|
|
789
|
-
onProgress?.(i + 1, orders.length)
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
if (submittedOrders.length > 0) {
|
|
793
|
-
this.context.logger(
|
|
794
|
-
`Successfully submitted ${submittedOrders.length}/${orders.length} ${pluralize(submittedOrders.length, "listing")}`,
|
|
795
|
-
)
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
if (failedOrders.length > 0) {
|
|
799
|
-
this.context.logger(
|
|
800
|
-
`Failed to submit ${failedOrders.length}/${orders.length} ${pluralize(failedOrders.length, "listing")}`,
|
|
801
|
-
)
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
return {
|
|
805
|
-
successful: submittedOrders,
|
|
806
|
-
failed: failedOrders,
|
|
807
|
-
}
|
|
838
|
+
),
|
|
839
|
+
continueOnError,
|
|
840
|
+
onProgress,
|
|
841
|
+
})
|
|
808
842
|
}
|
|
809
843
|
|
|
810
844
|
/**
|
|
@@ -819,7 +853,9 @@ export class OrdersManager {
|
|
|
819
853
|
* @param options.offers Array of offer parameters. Each offer requires asset, amount, and optionally other offer parameters.
|
|
820
854
|
* @param options.accountAddress Address of the wallet making the offers
|
|
821
855
|
* @param options.continueOnError If true, continue submitting remaining offers even if some fail. Default: false (throw on first error).
|
|
822
|
-
* @param options.onProgress Optional callback for progress updates. Called after each
|
|
856
|
+
* @param options.onProgress Optional callback for progress updates. Called after each
|
|
857
|
+
* offer that finishes, whether it succeeded or failed. A failure when `continueOnError`
|
|
858
|
+
* is false throws instead, so that offer is never reported.
|
|
823
859
|
* @returns {@link BulkOrderResult} containing successful orders and any failures.
|
|
824
860
|
*
|
|
825
861
|
* @throws Error if offers array is empty
|
|
@@ -852,30 +888,10 @@ export class OrdersManager {
|
|
|
852
888
|
|
|
853
889
|
// If only one offer, use normal signature to avoid bulk signature overhead
|
|
854
890
|
if (offers.length === 1) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
})
|
|
860
|
-
return {
|
|
861
|
-
successful: [order],
|
|
862
|
-
failed: [],
|
|
863
|
-
}
|
|
864
|
-
} catch (error) {
|
|
865
|
-
if (continueOnError) {
|
|
866
|
-
return {
|
|
867
|
-
successful: [],
|
|
868
|
-
failed: [
|
|
869
|
-
{
|
|
870
|
-
index: 0,
|
|
871
|
-
order: {} as ProtocolData, // Order wasn't created
|
|
872
|
-
error: error as Error,
|
|
873
|
-
},
|
|
874
|
-
],
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
throw error
|
|
878
|
-
}
|
|
891
|
+
return this.createOneForBulk(
|
|
892
|
+
() => this.createOffer({ ...offers[0], accountAddress }),
|
|
893
|
+
continueOnError,
|
|
894
|
+
)
|
|
879
895
|
}
|
|
880
896
|
|
|
881
897
|
await this.context.requireAccountIsAvailable(accountAddress)
|
|
@@ -963,9 +979,7 @@ export class OrdersManager {
|
|
|
963
979
|
: oneMonthFromNowInSeconds().toString(),
|
|
964
980
|
zone: metadata.zone,
|
|
965
981
|
domain: metadata.domain,
|
|
966
|
-
salt: metadata.salt
|
|
967
|
-
? BigInt(metadata.salt ?? 0).toString()
|
|
968
|
-
: undefined,
|
|
982
|
+
salt: normalizeSalt(metadata.salt),
|
|
969
983
|
restrictedByZone: metadata.zone !== ZERO_ADDRESS,
|
|
970
984
|
allowPartialFills: true,
|
|
971
985
|
}
|
|
@@ -981,61 +995,17 @@ export class OrdersManager {
|
|
|
981
995
|
|
|
982
996
|
const orders = await executeAllActions()
|
|
983
997
|
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
const submittedOrders: Offer[] = []
|
|
991
|
-
const failedOrders: BulkOrderResult["failed"] = []
|
|
992
|
-
|
|
993
|
-
for (let i = 0; i < orders.length; i++) {
|
|
994
|
-
this.context.logger(`Submitting offer ${i + 1}/${orders.length}...`)
|
|
995
|
-
try {
|
|
996
|
-
const submittedOrder = await this.context.api.postOffer(
|
|
997
|
-
orders[i],
|
|
998
|
+
return this.submitBulkSignedOrders({
|
|
999
|
+
orders,
|
|
1000
|
+
noun: "offer",
|
|
1001
|
+
post: order =>
|
|
1002
|
+
this.context.api.postOffer(
|
|
1003
|
+
order,
|
|
998
1004
|
this.context.seaport.contract.target as string,
|
|
999
|
-
)
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
const errorMessage = (error as Error).message
|
|
1004
|
-
this.context.logger(
|
|
1005
|
-
`Failed offer ${i + 1}/${orders.length}: ${errorMessage}`,
|
|
1006
|
-
)
|
|
1007
|
-
failedOrders.push({
|
|
1008
|
-
index: i,
|
|
1009
|
-
order: orders[i],
|
|
1010
|
-
error: error as Error,
|
|
1011
|
-
})
|
|
1012
|
-
|
|
1013
|
-
// If not continuing on error, throw immediately
|
|
1014
|
-
if (!continueOnError) {
|
|
1015
|
-
throw error
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
// Call progress callback after each offer (successful or failed)
|
|
1020
|
-
onProgress?.(i + 1, orders.length)
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
if (submittedOrders.length > 0) {
|
|
1024
|
-
this.context.logger(
|
|
1025
|
-
`Successfully submitted ${submittedOrders.length}/${orders.length} ${pluralize(submittedOrders.length, "offer")}`,
|
|
1026
|
-
)
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
if (failedOrders.length > 0) {
|
|
1030
|
-
this.context.logger(
|
|
1031
|
-
`Failed to submit ${failedOrders.length}/${orders.length} ${pluralize(failedOrders.length, "offer")}`,
|
|
1032
|
-
)
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
return {
|
|
1036
|
-
successful: submittedOrders,
|
|
1037
|
-
failed: failedOrders,
|
|
1038
|
-
}
|
|
1005
|
+
),
|
|
1006
|
+
continueOnError,
|
|
1007
|
+
onProgress,
|
|
1008
|
+
})
|
|
1039
1009
|
}
|
|
1040
1010
|
|
|
1041
1011
|
/**
|
|
@@ -1137,7 +1107,7 @@ export class OrdersManager {
|
|
|
1137
1107
|
expirationTime?.toString() ?? oneMonthFromNowInSeconds().toString(),
|
|
1138
1108
|
zone: buildOfferResult.partialParameters.zone,
|
|
1139
1109
|
domain,
|
|
1140
|
-
salt:
|
|
1110
|
+
salt: normalizeSalt(salt),
|
|
1141
1111
|
restrictedByZone: true,
|
|
1142
1112
|
allowPartialFills: true,
|
|
1143
1113
|
}
|
package/src/types.ts
CHANGED
|
@@ -12,6 +12,9 @@ import type {
|
|
|
12
12
|
import type { Listing, Offer } from "./api/types"
|
|
13
13
|
import type { OrderV2 } from "./orders/types"
|
|
14
14
|
import type { Camelize } from "./utils/case"
|
|
15
|
+
import type { FetchImpl } from "./utils/fetchTransport"
|
|
16
|
+
|
|
17
|
+
export type { FetchImpl } from "./utils/fetchTransport"
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Numeric type for amounts (replaces ethers BigNumberish).
|
|
@@ -139,8 +142,8 @@ export interface OpenSeaAPIConfig {
|
|
|
139
142
|
*
|
|
140
143
|
* It receives the fully built URL and init, including the API key and auth headers, so treat
|
|
141
144
|
* anything it logs or caches as sensitive. It is called for the instance's own requests; the
|
|
142
|
-
* static `OpenSeaAPI.requestInstantApiKey` has no instance to read it from and
|
|
143
|
-
*
|
|
145
|
+
* static `OpenSeaAPI.requestInstantApiKey` has no instance to read it from and takes its own
|
|
146
|
+
* transport as an argument.
|
|
144
147
|
*
|
|
145
148
|
* A cache built on this must key on the credentials as well as the URL, and must not cache
|
|
146
149
|
* anything but GET. Two callers with different API keys or auth tokens can see different
|
|
@@ -167,7 +170,7 @@ export interface OpenSeaAPIConfig {
|
|
|
167
170
|
* })
|
|
168
171
|
* ```
|
|
169
172
|
*/
|
|
170
|
-
fetch?:
|
|
173
|
+
fetch?: FetchImpl
|
|
171
174
|
}
|
|
172
175
|
|
|
173
176
|
/**
|
|
@@ -388,6 +391,9 @@ export interface RequestOptions {
|
|
|
388
391
|
* The return type stays the camelized view, so the caller is responsible for
|
|
389
392
|
* passing a `T` whose keys already match the wire shape. `GetTraitsResponse`
|
|
390
393
|
* qualifies because `Camelize<T>` passes index signatures through unchanged.
|
|
394
|
+
* Setting this to `false` with a `T` that has snake_case keys makes the
|
|
395
|
+
* declared type wrong: it will claim camelCase properties the response does
|
|
396
|
+
* not have. The flag does not narrow the return type, so nothing catches it.
|
|
391
397
|
*/
|
|
392
398
|
camelizeResponse?: boolean
|
|
393
399
|
}
|
package/src/utils/case.ts
CHANGED
|
@@ -136,6 +136,28 @@ type SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}`
|
|
|
136
136
|
*
|
|
137
137
|
* SDK consumers see camelCase types even though api-types ships snake_case —
|
|
138
138
|
* the runtime {@link camelizeKeysDeep} keeps shapes in sync.
|
|
139
|
+
*
|
|
140
|
+
* Reach for this when a response has no dedicated camelized alias in this
|
|
141
|
+
* package: `Camelize<SomeWireType>` is the shape an SDK method returns, and
|
|
142
|
+
* the raw `@opensea/api-types` type is not. Annotating an SDK return value
|
|
143
|
+
* with the raw type leaves every renamed field `undefined` at runtime, while
|
|
144
|
+
* single-word keys such as `address` survive and still read correctly, and the
|
|
145
|
+
* compiler only catches it when the wire type has a required snake_case key
|
|
146
|
+
* somewhere in its tree.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* import type { AccountResolveResponse } from "@opensea/api-types"
|
|
151
|
+
* import type { Camelize } from "@opensea/sdk"
|
|
152
|
+
*
|
|
153
|
+
* // Wrong: compiles, and `ens_name` is undefined at runtime.
|
|
154
|
+
* const bad: AccountResolveResponse =
|
|
155
|
+
* await sdk.api.accounts.resolveAccount("vitalik.eth")
|
|
156
|
+
*
|
|
157
|
+
* // Right.
|
|
158
|
+
* const good: Camelize<AccountResolveResponse> =
|
|
159
|
+
* await sdk.api.accounts.resolveAccount("vitalik.eth")
|
|
160
|
+
* ```
|
|
139
161
|
*/
|
|
140
162
|
export type Camelize<T> = T extends Date
|
|
141
163
|
? T
|