@opensea/sdk 9.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.
- package/LICENSE +7 -0
- package/README.md +70 -0
- package/lib/api/accounts.d.ts +27 -0
- package/lib/api/accounts.js +46 -0
- package/lib/api/accounts.js.map +1 -0
- package/lib/api/api.d.ts +489 -0
- package/lib/api/api.js +754 -0
- package/lib/api/api.js.map +1 -0
- package/lib/api/apiPaths.d.ts +46 -0
- package/lib/api/apiPaths.js +176 -0
- package/lib/api/apiPaths.js.map +1 -0
- package/lib/api/chains.d.ts +13 -0
- package/lib/api/chains.js +22 -0
- package/lib/api/chains.js.map +1 -0
- package/lib/api/collections.d.ts +34 -0
- package/lib/api/collections.js +80 -0
- package/lib/api/collections.js.map +1 -0
- package/lib/api/drops.d.ts +21 -0
- package/lib/api/drops.js +39 -0
- package/lib/api/drops.js.map +1 -0
- package/lib/api/events.d.ts +26 -0
- package/lib/api/events.js +43 -0
- package/lib/api/events.js.map +1 -0
- package/lib/api/fetcher.d.ts +24 -0
- package/lib/api/fetcher.js +3 -0
- package/lib/api/fetcher.js.map +1 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +19 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/listings.d.ts +44 -0
- package/lib/api/listings.js +88 -0
- package/lib/api/listings.js.map +1 -0
- package/lib/api/nfts.d.ts +39 -0
- package/lib/api/nfts.js +79 -0
- package/lib/api/nfts.js.map +1 -0
- package/lib/api/offers.d.ts +54 -0
- package/lib/api/offers.js +124 -0
- package/lib/api/offers.js.map +1 -0
- package/lib/api/orders.d.ts +50 -0
- package/lib/api/orders.js +153 -0
- package/lib/api/orders.js.map +1 -0
- package/lib/api/search.d.ts +13 -0
- package/lib/api/search.js +22 -0
- package/lib/api/search.js.map +1 -0
- package/lib/api/tokens.d.ts +25 -0
- package/lib/api/tokens.js +43 -0
- package/lib/api/tokens.js.map +1 -0
- package/lib/api/types.d.ts +1113 -0
- package/lib/api/types.js +65 -0
- package/lib/api/types.js.map +1 -0
- package/lib/constants.d.ts +22 -0
- package/lib/constants.js +52 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/orders/privateListings.d.ts +12 -0
- package/lib/orders/privateListings.js +130 -0
- package/lib/orders/privateListings.js.map +1 -0
- package/lib/orders/types.d.ts +160 -0
- package/lib/orders/types.js +10 -0
- package/lib/orders/types.js.map +1 -0
- package/lib/orders/utils.d.ts +89 -0
- package/lib/orders/utils.js +177 -0
- package/lib/orders/utils.js.map +1 -0
- package/lib/sdk/assets.d.ts +104 -0
- package/lib/sdk/assets.js +398 -0
- package/lib/sdk/assets.js.map +1 -0
- package/lib/sdk/cancellation.d.ts +97 -0
- package/lib/sdk/cancellation.js +235 -0
- package/lib/sdk/cancellation.js.map +1 -0
- package/lib/sdk/context.d.ts +28 -0
- package/lib/sdk/context.js +3 -0
- package/lib/sdk/context.js.map +1 -0
- package/lib/sdk/fulfillment.d.ts +153 -0
- package/lib/sdk/fulfillment.js +298 -0
- package/lib/sdk/fulfillment.js.map +1 -0
- package/lib/sdk/orders.d.ts +253 -0
- package/lib/sdk/orders.js +679 -0
- package/lib/sdk/orders.js.map +1 -0
- package/lib/sdk/tokens.d.ts +31 -0
- package/lib/sdk/tokens.js +65 -0
- package/lib/sdk/tokens.js.map +1 -0
- package/lib/sdk.d.ts +560 -0
- package/lib/sdk.js +693 -0
- package/lib/sdk.js.map +1 -0
- package/lib/src/api/accounts.d.ts +18 -0
- package/lib/src/api/accounts.js +30 -0
- package/lib/src/api/accounts.js.map +1 -0
- package/lib/src/api/api.d.ts +429 -0
- package/lib/src/api/api.js +652 -0
- package/lib/src/api/api.js.map +1 -0
- package/lib/src/api/apiPaths.d.ts +37 -0
- package/lib/src/api/apiPaths.js +140 -0
- package/lib/src/api/apiPaths.js.map +1 -0
- package/lib/src/api/collections.d.ts +26 -0
- package/lib/src/api/collections.js +57 -0
- package/lib/src/api/collections.js.map +1 -0
- package/lib/src/api/events.d.ts +26 -0
- package/lib/src/api/events.js +42 -0
- package/lib/src/api/events.js.map +1 -0
- package/lib/src/api/fetcher.d.ts +24 -0
- package/lib/src/api/fetcher.js +3 -0
- package/lib/src/api/fetcher.js.map +1 -0
- package/lib/src/api/index.d.ts +2 -0
- package/lib/src/api/index.js +19 -0
- package/lib/src/api/index.js.map +1 -0
- package/lib/src/api/listings.d.ts +44 -0
- package/lib/src/api/listings.js +86 -0
- package/lib/src/api/listings.js.map +1 -0
- package/lib/src/api/nfts.d.ts +35 -0
- package/lib/src/api/nfts.js +66 -0
- package/lib/src/api/nfts.js.map +1 -0
- package/lib/src/api/offers.d.ts +54 -0
- package/lib/src/api/offers.js +122 -0
- package/lib/src/api/offers.js.map +1 -0
- package/lib/src/api/orders.d.ts +50 -0
- package/lib/src/api/orders.js +151 -0
- package/lib/src/api/orders.js.map +1 -0
- package/lib/src/api/search.d.ts +13 -0
- package/lib/src/api/search.js +21 -0
- package/lib/src/api/search.js.map +1 -0
- package/lib/src/api/tokens.d.ts +25 -0
- package/lib/src/api/tokens.js +42 -0
- package/lib/src/api/tokens.js.map +1 -0
- package/lib/src/api/types.d.ts +840 -0
- package/lib/src/api/types.js +65 -0
- package/lib/src/api/types.js.map +1 -0
- package/lib/src/constants.d.ts +22 -0
- package/lib/src/constants.js +52 -0
- package/lib/src/constants.js.map +1 -0
- package/lib/src/index.d.ts +18 -0
- package/lib/src/index.js +24 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/orders/privateListings.d.ts +12 -0
- package/lib/src/orders/privateListings.js +130 -0
- package/lib/src/orders/privateListings.js.map +1 -0
- package/lib/src/orders/types.d.ts +160 -0
- package/lib/src/orders/types.js +10 -0
- package/lib/src/orders/types.js.map +1 -0
- package/lib/src/orders/utils.d.ts +89 -0
- package/lib/src/orders/utils.js +177 -0
- package/lib/src/orders/utils.js.map +1 -0
- package/lib/src/sdk/assets.d.ts +104 -0
- package/lib/src/sdk/assets.js +397 -0
- package/lib/src/sdk/assets.js.map +1 -0
- package/lib/src/sdk/cancellation.d.ts +97 -0
- package/lib/src/sdk/cancellation.js +234 -0
- package/lib/src/sdk/cancellation.js.map +1 -0
- package/lib/src/sdk/context.d.ts +28 -0
- package/lib/src/sdk/context.js +3 -0
- package/lib/src/sdk/context.js.map +1 -0
- package/lib/src/sdk/fulfillment.d.ts +153 -0
- package/lib/src/sdk/fulfillment.js +296 -0
- package/lib/src/sdk/fulfillment.js.map +1 -0
- package/lib/src/sdk/orders.d.ts +253 -0
- package/lib/src/sdk/orders.js +677 -0
- package/lib/src/sdk/orders.js.map +1 -0
- package/lib/src/sdk/tokens.d.ts +31 -0
- package/lib/src/sdk/tokens.js +64 -0
- package/lib/src/sdk/tokens.js.map +1 -0
- package/lib/src/sdk.d.ts +560 -0
- package/lib/src/sdk.js +675 -0
- package/lib/src/sdk.js.map +1 -0
- package/lib/src/typechain/contracts/ERC1155.d.ts +236 -0
- package/lib/src/typechain/contracts/ERC1155.js +3 -0
- package/lib/src/typechain/contracts/ERC1155.js.map +1 -0
- package/lib/src/typechain/contracts/ERC20.d.ts +141 -0
- package/lib/src/typechain/contracts/ERC20.js +3 -0
- package/lib/src/typechain/contracts/ERC20.js.map +1 -0
- package/lib/src/typechain/contracts/ERC721.d.ts +213 -0
- package/lib/src/typechain/contracts/ERC721.js +3 -0
- package/lib/src/typechain/contracts/ERC721.js.map +1 -0
- package/lib/src/typechain/contracts/Multicall3.d.ts +57 -0
- package/lib/src/typechain/contracts/Multicall3.js +3 -0
- package/lib/src/typechain/contracts/Multicall3.js.map +1 -0
- package/lib/src/typechain/contracts/TransferHelper.d.ts +55 -0
- package/lib/src/typechain/contracts/TransferHelper.js +3 -0
- package/lib/src/typechain/contracts/TransferHelper.js.map +1 -0
- package/lib/src/typechain/contracts/common.d.ts +50 -0
- package/lib/src/typechain/contracts/common.js +3 -0
- package/lib/src/typechain/contracts/common.js.map +1 -0
- package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
- package/lib/src/typechain/contracts/factories/ERC1155__factory.js +332 -0
- package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
- package/lib/src/typechain/contracts/factories/ERC20__factory.js +240 -0
- package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
- package/lib/src/typechain/contracts/factories/ERC721__factory.js +351 -0
- package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
- package/lib/src/typechain/contracts/factories/Multicall3__factory.js +68 -0
- package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +71 -0
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/index.d.ts +5 -0
- package/lib/src/typechain/contracts/factories/index.js +17 -0
- package/lib/src/typechain/contracts/factories/index.js.map +1 -0
- package/lib/src/typechain/contracts/index.d.ts +11 -0
- package/lib/src/typechain/contracts/index.js +48 -0
- package/lib/src/typechain/contracts/index.js.map +1 -0
- package/lib/src/types.d.ts +387 -0
- package/lib/src/types.js +127 -0
- package/lib/src/types.js.map +1 -0
- package/lib/src/utils/chain.d.ts +60 -0
- package/lib/src/utils/chain.js +248 -0
- package/lib/src/utils/chain.js.map +1 -0
- package/lib/src/utils/converters.d.ts +37 -0
- package/lib/src/utils/converters.js +137 -0
- package/lib/src/utils/converters.js.map +1 -0
- package/lib/src/utils/dateHelper.d.ts +38 -0
- package/lib/src/utils/dateHelper.js +52 -0
- package/lib/src/utils/dateHelper.js.map +1 -0
- package/lib/src/utils/fees.d.ts +13 -0
- package/lib/src/utils/fees.js +29 -0
- package/lib/src/utils/fees.js.map +1 -0
- package/lib/src/utils/index.d.ts +2 -0
- package/lib/src/utils/index.js +19 -0
- package/lib/src/utils/index.js.map +1 -0
- package/lib/src/utils/protocol.d.ts +75 -0
- package/lib/src/utils/protocol.js +161 -0
- package/lib/src/utils/protocol.js.map +1 -0
- package/lib/src/utils/rateLimit.d.ts +34 -0
- package/lib/src/utils/rateLimit.js +97 -0
- package/lib/src/utils/rateLimit.js.map +1 -0
- package/lib/src/utils/stringHelper.d.ts +18 -0
- package/lib/src/utils/stringHelper.js +24 -0
- package/lib/src/utils/stringHelper.js.map +1 -0
- package/lib/src/utils/utils.d.ts +18 -0
- package/lib/src/utils/utils.js +45 -0
- package/lib/src/utils/utils.js.map +1 -0
- package/lib/typechain/contracts/ERC1155.d.ts +236 -0
- package/lib/typechain/contracts/ERC1155.js +3 -0
- package/lib/typechain/contracts/ERC1155.js.map +1 -0
- package/lib/typechain/contracts/ERC20.d.ts +141 -0
- package/lib/typechain/contracts/ERC20.js +3 -0
- package/lib/typechain/contracts/ERC20.js.map +1 -0
- package/lib/typechain/contracts/ERC721.d.ts +213 -0
- package/lib/typechain/contracts/ERC721.js +3 -0
- package/lib/typechain/contracts/ERC721.js.map +1 -0
- package/lib/typechain/contracts/Multicall3.d.ts +57 -0
- package/lib/typechain/contracts/Multicall3.js +3 -0
- package/lib/typechain/contracts/Multicall3.js.map +1 -0
- package/lib/typechain/contracts/TransferHelper.d.ts +55 -0
- package/lib/typechain/contracts/TransferHelper.js +3 -0
- package/lib/typechain/contracts/TransferHelper.js.map +1 -0
- package/lib/typechain/contracts/common.d.ts +50 -0
- package/lib/typechain/contracts/common.js +3 -0
- package/lib/typechain/contracts/common.js.map +1 -0
- package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
- package/lib/typechain/contracts/factories/ERC1155__factory.js +332 -0
- package/lib/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
- package/lib/typechain/contracts/factories/ERC20__factory.js +240 -0
- package/lib/typechain/contracts/factories/ERC20__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
- package/lib/typechain/contracts/factories/ERC721__factory.js +351 -0
- package/lib/typechain/contracts/factories/ERC721__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
- package/lib/typechain/contracts/factories/Multicall3__factory.js +68 -0
- package/lib/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
- package/lib/typechain/contracts/factories/TransferHelper__factory.js +71 -0
- package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/index.d.ts +5 -0
- package/lib/typechain/contracts/factories/index.js +17 -0
- package/lib/typechain/contracts/factories/index.js.map +1 -0
- package/lib/typechain/contracts/index.d.ts +11 -0
- package/lib/typechain/contracts/index.js +48 -0
- package/lib/typechain/contracts/index.js.map +1 -0
- package/lib/types.d.ts +389 -0
- package/lib/types.js +129 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/chain.d.ts +64 -0
- package/lib/utils/chain.js +211 -0
- package/lib/utils/chain.js.map +1 -0
- package/lib/utils/chainIds.generated.d.ts +7 -0
- package/lib/utils/chainIds.generated.js +37 -0
- package/lib/utils/chainIds.generated.js.map +1 -0
- package/lib/utils/converters.d.ts +37 -0
- package/lib/utils/converters.js +137 -0
- package/lib/utils/converters.js.map +1 -0
- package/lib/utils/dateHelper.d.ts +38 -0
- package/lib/utils/dateHelper.js +52 -0
- package/lib/utils/dateHelper.js.map +1 -0
- package/lib/utils/fees.d.ts +13 -0
- package/lib/utils/fees.js +29 -0
- package/lib/utils/fees.js.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +19 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/protocol.d.ts +75 -0
- package/lib/utils/protocol.js +161 -0
- package/lib/utils/protocol.js.map +1 -0
- package/lib/utils/rateLimit.d.ts +34 -0
- package/lib/utils/rateLimit.js +97 -0
- package/lib/utils/rateLimit.js.map +1 -0
- package/lib/utils/stringHelper.d.ts +18 -0
- package/lib/utils/stringHelper.js +24 -0
- package/lib/utils/stringHelper.js.map +1 -0
- package/lib/utils/utils.d.ts +18 -0
- package/lib/utils/utils.js +45 -0
- package/lib/utils/utils.js.map +1 -0
- package/package.json +72 -0
- package/src/abi/ERC1155.json +314 -0
- package/src/abi/ERC20.json +222 -0
- package/src/abi/ERC721.json +333 -0
- package/src/abi/Multicall3.json +50 -0
- package/src/abi/TransferHelper.json +53 -0
- package/src/api/accounts.ts +69 -0
- package/src/api/api.ts +1152 -0
- package/src/api/apiPaths.ts +208 -0
- package/src/api/chains.ts +18 -0
- package/src/api/collections.ts +120 -0
- package/src/api/drops.ts +49 -0
- package/src/api/events.ts +71 -0
- package/src/api/fetcher.ts +31 -0
- package/src/api/index.ts +2 -0
- package/src/api/listings.ts +126 -0
- package/src/api/nfts.ts +144 -0
- package/src/api/offers.ts +242 -0
- package/src/api/orders.ts +283 -0
- package/src/api/search.ts +21 -0
- package/src/api/tokens.ts +67 -0
- package/src/api/types.ts +1210 -0
- package/src/constants.ts +90 -0
- package/src/index.ts +22 -0
- package/src/orders/privateListings.ts +173 -0
- package/src/orders/types.ts +191 -0
- package/src/orders/utils.ts +253 -0
- package/src/sdk/assets.ts +591 -0
- package/src/sdk/cancellation.ts +346 -0
- package/src/sdk/context.ts +33 -0
- package/src/sdk/fulfillment.ts +478 -0
- package/src/sdk/orders.ts +1149 -0
- package/src/sdk/tokens.ts +95 -0
- package/src/sdk.ts +1051 -0
- package/src/typechain/contracts/ERC1155.ts +440 -0
- package/src/typechain/contracts/ERC20.ts +286 -0
- package/src/typechain/contracts/ERC721.ts +412 -0
- package/src/typechain/contracts/Multicall3.ts +117 -0
- package/src/typechain/contracts/TransferHelper.ts +122 -0
- package/src/typechain/contracts/common.ts +131 -0
- package/src/typechain/contracts/factories/ERC1155__factory.ts +331 -0
- package/src/typechain/contracts/factories/ERC20__factory.ts +239 -0
- package/src/typechain/contracts/factories/ERC721__factory.ts +350 -0
- package/src/typechain/contracts/factories/Multicall3__factory.ts +67 -0
- package/src/typechain/contracts/factories/TransferHelper__factory.ts +76 -0
- package/src/typechain/contracts/factories/index.ts +8 -0
- package/src/typechain/contracts/index.ts +14 -0
- package/src/types.ts +413 -0
- package/src/utils/chain.ts +224 -0
- package/src/utils/chainIds.generated.ts +34 -0
- package/src/utils/converters.ts +145 -0
- package/src/utils/dateHelper.ts +48 -0
- package/src/utils/fees.ts +31 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/protocol.ts +185 -0
- package/src/utils/rateLimit.ts +147 -0
- package/src/utils/stringHelper.ts +25 -0
- package/src/utils/utils.ts +36 -0
package/src/api/nfts.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Chain } from "../types"
|
|
2
|
+
import {
|
|
3
|
+
getContractPath,
|
|
4
|
+
getListNFTsByAccountPath,
|
|
5
|
+
getListNFTsByCollectionPath,
|
|
6
|
+
getListNFTsByContractPath,
|
|
7
|
+
getNFTPath,
|
|
8
|
+
getRefreshMetadataPath,
|
|
9
|
+
getValidateMetadataPath,
|
|
10
|
+
} from "./apiPaths"
|
|
11
|
+
import type { Fetcher } from "./fetcher"
|
|
12
|
+
import type {
|
|
13
|
+
GetContractResponse,
|
|
14
|
+
GetNFTResponse,
|
|
15
|
+
ListNFTsResponse,
|
|
16
|
+
ValidateMetadataResponse,
|
|
17
|
+
} from "./types"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* NFT-related API operations
|
|
21
|
+
*/
|
|
22
|
+
export class NFTsAPI {
|
|
23
|
+
constructor(
|
|
24
|
+
private fetcher: Fetcher,
|
|
25
|
+
private chain: Chain,
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Fetch multiple NFTs for a collection.
|
|
30
|
+
*/
|
|
31
|
+
async getNFTsByCollection(
|
|
32
|
+
slug: string,
|
|
33
|
+
limit: number | undefined = undefined,
|
|
34
|
+
next: string | undefined = undefined,
|
|
35
|
+
): Promise<ListNFTsResponse> {
|
|
36
|
+
const response = await this.fetcher.get<ListNFTsResponse>(
|
|
37
|
+
getListNFTsByCollectionPath(slug),
|
|
38
|
+
{
|
|
39
|
+
limit,
|
|
40
|
+
next,
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
return response
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Fetch multiple NFTs for a contract.
|
|
48
|
+
*/
|
|
49
|
+
async getNFTsByContract(
|
|
50
|
+
address: string,
|
|
51
|
+
limit: number | undefined = undefined,
|
|
52
|
+
next: string | undefined = undefined,
|
|
53
|
+
chain: Chain = this.chain,
|
|
54
|
+
): Promise<ListNFTsResponse> {
|
|
55
|
+
const response = await this.fetcher.get<ListNFTsResponse>(
|
|
56
|
+
getListNFTsByContractPath(chain, address),
|
|
57
|
+
{
|
|
58
|
+
limit,
|
|
59
|
+
next,
|
|
60
|
+
},
|
|
61
|
+
)
|
|
62
|
+
return response
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Fetch NFTs owned by an account.
|
|
67
|
+
*/
|
|
68
|
+
async getNFTsByAccount(
|
|
69
|
+
address: string,
|
|
70
|
+
limit: number | undefined = undefined,
|
|
71
|
+
next: string | undefined = undefined,
|
|
72
|
+
chain = this.chain,
|
|
73
|
+
): Promise<ListNFTsResponse> {
|
|
74
|
+
const response = await this.fetcher.get<ListNFTsResponse>(
|
|
75
|
+
getListNFTsByAccountPath(chain, address),
|
|
76
|
+
{
|
|
77
|
+
limit,
|
|
78
|
+
next,
|
|
79
|
+
},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return response
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Fetch metadata, traits, ownership information, and rarity for a single NFT.
|
|
87
|
+
*/
|
|
88
|
+
async getNFT(
|
|
89
|
+
address: string,
|
|
90
|
+
identifier: string,
|
|
91
|
+
chain = this.chain,
|
|
92
|
+
): Promise<GetNFTResponse> {
|
|
93
|
+
const response = await this.fetcher.get<GetNFTResponse>(
|
|
94
|
+
getNFTPath(chain, address, identifier),
|
|
95
|
+
)
|
|
96
|
+
return response
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Force refresh the metadata for an NFT.
|
|
101
|
+
*/
|
|
102
|
+
async refreshNFTMetadata(
|
|
103
|
+
address: string,
|
|
104
|
+
identifier: string,
|
|
105
|
+
chain: Chain = this.chain,
|
|
106
|
+
): Promise<Response> {
|
|
107
|
+
const response = await this.fetcher.post<Response>(
|
|
108
|
+
getRefreshMetadataPath(chain, address, identifier),
|
|
109
|
+
{},
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
return response
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Fetch smart contract information for a given chain and address.
|
|
117
|
+
*/
|
|
118
|
+
async getContract(
|
|
119
|
+
address: string,
|
|
120
|
+
chain: Chain = this.chain,
|
|
121
|
+
): Promise<GetContractResponse> {
|
|
122
|
+
const response = await this.fetcher.get<GetContractResponse>(
|
|
123
|
+
getContractPath(chain, address),
|
|
124
|
+
)
|
|
125
|
+
return response
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Validate NFT metadata by fetching and parsing it.
|
|
130
|
+
*/
|
|
131
|
+
async validateMetadata(
|
|
132
|
+
address: string,
|
|
133
|
+
identifier: string,
|
|
134
|
+
chain: Chain = this.chain,
|
|
135
|
+
ignoreCachedItemUrls?: boolean,
|
|
136
|
+
): Promise<ValidateMetadataResponse> {
|
|
137
|
+
let path = getValidateMetadataPath(chain, address, identifier)
|
|
138
|
+
if (ignoreCachedItemUrls !== undefined) {
|
|
139
|
+
path += `?ignoreCachedItemUrls=${ignoreCachedItemUrls}`
|
|
140
|
+
}
|
|
141
|
+
const response = await this.fetcher.post<ValidateMetadataResponse>(path)
|
|
142
|
+
return response
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type { ProtocolData } from "../orders/types"
|
|
2
|
+
import {
|
|
3
|
+
getBuildCollectionOfferPayload,
|
|
4
|
+
getPostCollectionOfferPayload,
|
|
5
|
+
serializeOrdersQueryOptions,
|
|
6
|
+
} from "../orders/utils"
|
|
7
|
+
import { type Chain, OrderSide } from "../types"
|
|
8
|
+
import {
|
|
9
|
+
getAllOffersAPIPath,
|
|
10
|
+
getBestOfferAPIPath,
|
|
11
|
+
getBuildOfferPath,
|
|
12
|
+
getCollectionOffersPath,
|
|
13
|
+
getOrdersAPIPath,
|
|
14
|
+
getPostCollectionOfferPath,
|
|
15
|
+
getTraitOffersPath,
|
|
16
|
+
} from "./apiPaths"
|
|
17
|
+
import type { Fetcher } from "./fetcher"
|
|
18
|
+
import type {
|
|
19
|
+
BuildOfferResponse,
|
|
20
|
+
CollectionOffer,
|
|
21
|
+
GetBestOfferResponse,
|
|
22
|
+
GetOffersResponse,
|
|
23
|
+
} from "./types"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Validates trait parameters for collection offers.
|
|
27
|
+
* Used by both buildOffer and postCollectionOffer.
|
|
28
|
+
*/
|
|
29
|
+
function validateTraitParams(
|
|
30
|
+
traitType?: string,
|
|
31
|
+
traitValue?: string,
|
|
32
|
+
traits?: Array<{ type: string; value: string }>,
|
|
33
|
+
numericTraits?: Array<{ type: string; min?: number; max?: number }>,
|
|
34
|
+
) {
|
|
35
|
+
if (traits && traits.length > 0 && (traitType || traitValue)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"Cannot use both 'traits' array and individual 'traitType'/'traitValue' parameters. Please use only one approach.",
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
if (traitType || traitValue) {
|
|
41
|
+
if (!traitType || !traitValue) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"Both traitType and traitValue must be defined if one is defined.",
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (traits && traits.length > 0) {
|
|
48
|
+
for (const trait of traits) {
|
|
49
|
+
if (!trait.type || !trait.value) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Each trait must have both 'type' and 'value' properties.",
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (numericTraits && numericTraits.length > 0) {
|
|
57
|
+
for (const trait of numericTraits) {
|
|
58
|
+
if (!trait.type) {
|
|
59
|
+
throw new Error("Each numeric trait must have a 'type' property.")
|
|
60
|
+
}
|
|
61
|
+
if (trait.min === undefined && trait.max === undefined) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Numeric trait '${trait.type}' must have at least one of 'min' or 'max'.`,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
trait.min !== undefined &&
|
|
68
|
+
trait.max !== undefined &&
|
|
69
|
+
trait.min > trait.max
|
|
70
|
+
) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Numeric trait '${trait.type}': 'min' (${trait.min}) must be <= 'max' (${trait.max}).`,
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Offer-related API operations
|
|
81
|
+
*/
|
|
82
|
+
export class OffersAPI {
|
|
83
|
+
constructor(
|
|
84
|
+
private fetcher: Fetcher,
|
|
85
|
+
private chain: Chain,
|
|
86
|
+
) {}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Gets all offers for a given collection.
|
|
90
|
+
*/
|
|
91
|
+
async getAllOffers(
|
|
92
|
+
collectionSlug: string,
|
|
93
|
+
limit?: number,
|
|
94
|
+
next?: string,
|
|
95
|
+
): Promise<GetOffersResponse> {
|
|
96
|
+
const response = await this.fetcher.get<GetOffersResponse>(
|
|
97
|
+
getAllOffersAPIPath(collectionSlug),
|
|
98
|
+
{
|
|
99
|
+
limit,
|
|
100
|
+
next,
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
return response
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Gets trait offers for a given collection.
|
|
108
|
+
*/
|
|
109
|
+
async getTraitOffers(
|
|
110
|
+
collectionSlug: string,
|
|
111
|
+
type: string,
|
|
112
|
+
value: string,
|
|
113
|
+
limit?: number,
|
|
114
|
+
next?: string,
|
|
115
|
+
floatValue?: number,
|
|
116
|
+
intValue?: number,
|
|
117
|
+
): Promise<GetOffersResponse> {
|
|
118
|
+
const response = await this.fetcher.get<GetOffersResponse>(
|
|
119
|
+
getTraitOffersPath(collectionSlug),
|
|
120
|
+
{
|
|
121
|
+
type,
|
|
122
|
+
value,
|
|
123
|
+
limit,
|
|
124
|
+
next,
|
|
125
|
+
float_value: floatValue,
|
|
126
|
+
int_value: intValue,
|
|
127
|
+
},
|
|
128
|
+
)
|
|
129
|
+
return response
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Gets the best offer for a given token.
|
|
134
|
+
*/
|
|
135
|
+
async getBestOffer(
|
|
136
|
+
collectionSlug: string,
|
|
137
|
+
tokenId: string | number,
|
|
138
|
+
): Promise<GetBestOfferResponse> {
|
|
139
|
+
const response = await this.fetcher.get<GetBestOfferResponse>(
|
|
140
|
+
getBestOfferAPIPath(collectionSlug, tokenId),
|
|
141
|
+
)
|
|
142
|
+
return response
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Build a OpenSea collection offer.
|
|
147
|
+
*/
|
|
148
|
+
async buildOffer(
|
|
149
|
+
offererAddress: string,
|
|
150
|
+
quantity: number,
|
|
151
|
+
collectionSlug: string,
|
|
152
|
+
offerProtectionEnabled = true,
|
|
153
|
+
traitType?: string,
|
|
154
|
+
traitValue?: string,
|
|
155
|
+
traits?: Array<{ type: string; value: string }>,
|
|
156
|
+
numericTraits?: Array<{ type: string; min?: number; max?: number }>,
|
|
157
|
+
): Promise<BuildOfferResponse> {
|
|
158
|
+
validateTraitParams(traitType, traitValue, traits, numericTraits)
|
|
159
|
+
const payload = getBuildCollectionOfferPayload(
|
|
160
|
+
offererAddress,
|
|
161
|
+
quantity,
|
|
162
|
+
collectionSlug,
|
|
163
|
+
offerProtectionEnabled,
|
|
164
|
+
this.chain,
|
|
165
|
+
traitType,
|
|
166
|
+
traitValue,
|
|
167
|
+
traits,
|
|
168
|
+
numericTraits,
|
|
169
|
+
)
|
|
170
|
+
const response = await this.fetcher.post<BuildOfferResponse>(
|
|
171
|
+
getBuildOfferPath(),
|
|
172
|
+
payload,
|
|
173
|
+
)
|
|
174
|
+
return response
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get a list of collection offers for a given slug.
|
|
179
|
+
*/
|
|
180
|
+
async getCollectionOffers(
|
|
181
|
+
slug: string,
|
|
182
|
+
limit?: number,
|
|
183
|
+
next?: string,
|
|
184
|
+
): Promise<GetOffersResponse> {
|
|
185
|
+
return await this.fetcher.get<GetOffersResponse>(
|
|
186
|
+
getCollectionOffersPath(slug),
|
|
187
|
+
{
|
|
188
|
+
limit,
|
|
189
|
+
next,
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Post a collection offer to OpenSea.
|
|
196
|
+
*/
|
|
197
|
+
async postCollectionOffer(
|
|
198
|
+
order: ProtocolData,
|
|
199
|
+
slug: string,
|
|
200
|
+
traitType?: string,
|
|
201
|
+
traitValue?: string,
|
|
202
|
+
traits?: Array<{ type: string; value: string }>,
|
|
203
|
+
numericTraits?: Array<{ type: string; min?: number; max?: number }>,
|
|
204
|
+
): Promise<CollectionOffer | null> {
|
|
205
|
+
validateTraitParams(traitType, traitValue, traits, numericTraits)
|
|
206
|
+
const payload = getPostCollectionOfferPayload(
|
|
207
|
+
slug,
|
|
208
|
+
order,
|
|
209
|
+
this.chain,
|
|
210
|
+
traitType,
|
|
211
|
+
traitValue,
|
|
212
|
+
traits,
|
|
213
|
+
numericTraits,
|
|
214
|
+
)
|
|
215
|
+
return await this.fetcher.post<CollectionOffer>(
|
|
216
|
+
getPostCollectionOfferPath(),
|
|
217
|
+
payload,
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Gets all active offers for a specific NFT.
|
|
223
|
+
*/
|
|
224
|
+
async getNFTOffers(
|
|
225
|
+
assetContractAddress: string,
|
|
226
|
+
tokenId: string,
|
|
227
|
+
limit?: number,
|
|
228
|
+
next?: string,
|
|
229
|
+
chain: Chain = this.chain,
|
|
230
|
+
): Promise<GetOffersResponse> {
|
|
231
|
+
const response = await this.fetcher.get<GetOffersResponse>(
|
|
232
|
+
getOrdersAPIPath(chain, "seaport", OrderSide.OFFER),
|
|
233
|
+
serializeOrdersQueryOptions({
|
|
234
|
+
assetContractAddress,
|
|
235
|
+
tokenIds: [tokenId],
|
|
236
|
+
limit,
|
|
237
|
+
next,
|
|
238
|
+
}),
|
|
239
|
+
)
|
|
240
|
+
return response
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FulfillmentDataResponse,
|
|
3
|
+
ListingPostQueryResponse,
|
|
4
|
+
OfferPostQueryResponse,
|
|
5
|
+
OrderAPIOptions,
|
|
6
|
+
OrdersPostQueryResponse,
|
|
7
|
+
OrdersQueryOptions,
|
|
8
|
+
OrdersQueryResponse,
|
|
9
|
+
OrderV2,
|
|
10
|
+
ProtocolData,
|
|
11
|
+
} from "../orders/types"
|
|
12
|
+
import {
|
|
13
|
+
deserializeOrder,
|
|
14
|
+
getFulfillListingPayload,
|
|
15
|
+
getFulfillmentDataPath,
|
|
16
|
+
getFulfillOfferPayload,
|
|
17
|
+
serializeOrdersQueryOptions,
|
|
18
|
+
} from "../orders/utils"
|
|
19
|
+
import { type Chain, OrderSide } from "../types"
|
|
20
|
+
import {
|
|
21
|
+
getCancelOrderPath,
|
|
22
|
+
getOrderByHashPath,
|
|
23
|
+
getOrdersAPIPath,
|
|
24
|
+
} from "./apiPaths"
|
|
25
|
+
import type { Fetcher } from "./fetcher"
|
|
26
|
+
import type {
|
|
27
|
+
CancelOrderResponse,
|
|
28
|
+
GetOrderByHashResponse,
|
|
29
|
+
GetOrdersResponse,
|
|
30
|
+
Listing,
|
|
31
|
+
Offer,
|
|
32
|
+
} from "./types"
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Order-related API operations
|
|
36
|
+
*/
|
|
37
|
+
export class OrdersAPI {
|
|
38
|
+
constructor(
|
|
39
|
+
private fetcher: Fetcher,
|
|
40
|
+
private chain: Chain,
|
|
41
|
+
) {}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Gets an order from API based on query options.
|
|
45
|
+
* @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
|
|
46
|
+
*/
|
|
47
|
+
async getOrder({
|
|
48
|
+
side,
|
|
49
|
+
protocol = "seaport",
|
|
50
|
+
orderDirection = "desc",
|
|
51
|
+
orderBy = "created_date",
|
|
52
|
+
...restOptions
|
|
53
|
+
}: Omit<OrdersQueryOptions, "limit">): Promise<OrderV2> {
|
|
54
|
+
// Validate eth_price orderBy requires additional parameters
|
|
55
|
+
if (orderBy === "eth_price") {
|
|
56
|
+
const hasTokenId =
|
|
57
|
+
(restOptions.tokenIds?.length ?? 0) > 0 ||
|
|
58
|
+
restOptions.tokenId !== undefined
|
|
59
|
+
if (!restOptions.assetContractAddress || !hasTokenId) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
'When using orderBy: "eth_price", you must provide both assetContractAddress and tokenIds (or tokenId) parameters',
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { orders } = await this.fetcher.get<OrdersQueryResponse>(
|
|
67
|
+
getOrdersAPIPath(this.chain, protocol, side),
|
|
68
|
+
serializeOrdersQueryOptions({
|
|
69
|
+
limit: 1,
|
|
70
|
+
orderBy,
|
|
71
|
+
orderDirection,
|
|
72
|
+
...restOptions,
|
|
73
|
+
}),
|
|
74
|
+
)
|
|
75
|
+
if (orders.length === 0) {
|
|
76
|
+
throw new Error("Not found: no matching order found")
|
|
77
|
+
}
|
|
78
|
+
return deserializeOrder(orders[0])
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Gets a single order by its order hash.
|
|
83
|
+
* Returns the raw API response which can be either an Offer or Listing.
|
|
84
|
+
*/
|
|
85
|
+
async getOrderByHash(
|
|
86
|
+
orderHash: string,
|
|
87
|
+
protocolAddress: string,
|
|
88
|
+
chain: Chain = this.chain,
|
|
89
|
+
): Promise<GetOrderByHashResponse> {
|
|
90
|
+
const response = await this.fetcher.get<{
|
|
91
|
+
order: GetOrderByHashResponse
|
|
92
|
+
}>(getOrderByHashPath(chain, protocolAddress, orderHash))
|
|
93
|
+
return response.order
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Gets a list of orders from API based on query options.
|
|
98
|
+
* @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
|
|
99
|
+
*/
|
|
100
|
+
async getOrders({
|
|
101
|
+
side,
|
|
102
|
+
protocol = "seaport",
|
|
103
|
+
orderDirection = "desc",
|
|
104
|
+
orderBy = "created_date",
|
|
105
|
+
pageSize = 20,
|
|
106
|
+
...restOptions
|
|
107
|
+
}: Omit<OrdersQueryOptions, "limit"> & {
|
|
108
|
+
pageSize?: number
|
|
109
|
+
}): Promise<GetOrdersResponse> {
|
|
110
|
+
// Validate eth_price orderBy requires additional parameters
|
|
111
|
+
if (orderBy === "eth_price") {
|
|
112
|
+
const hasTokenId =
|
|
113
|
+
(restOptions.tokenIds?.length ?? 0) > 0 ||
|
|
114
|
+
restOptions.tokenId !== undefined
|
|
115
|
+
if (!restOptions.assetContractAddress || !hasTokenId) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
'When using orderBy: "eth_price", you must provide both assetContractAddress and tokenIds (or tokenId) parameters',
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const response = await this.fetcher.get<OrdersQueryResponse>(
|
|
123
|
+
getOrdersAPIPath(this.chain, protocol, side),
|
|
124
|
+
serializeOrdersQueryOptions({
|
|
125
|
+
limit: pageSize,
|
|
126
|
+
orderBy,
|
|
127
|
+
orderDirection,
|
|
128
|
+
...restOptions,
|
|
129
|
+
}),
|
|
130
|
+
)
|
|
131
|
+
return {
|
|
132
|
+
...response,
|
|
133
|
+
orders: response.orders.map(deserializeOrder),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Generate the data needed to fulfill a listing or an offer onchain.
|
|
139
|
+
*/
|
|
140
|
+
async generateFulfillmentData(
|
|
141
|
+
fulfillerAddress: string,
|
|
142
|
+
orderHash: string,
|
|
143
|
+
protocolAddress: string,
|
|
144
|
+
side: OrderSide,
|
|
145
|
+
assetContractAddress?: string,
|
|
146
|
+
tokenId?: string,
|
|
147
|
+
unitsToFill?: string,
|
|
148
|
+
recipientAddress?: string,
|
|
149
|
+
includeOptionalCreatorFees: boolean = false,
|
|
150
|
+
): Promise<FulfillmentDataResponse> {
|
|
151
|
+
let payload: object | null = null
|
|
152
|
+
if (side === OrderSide.LISTING) {
|
|
153
|
+
payload = getFulfillListingPayload(
|
|
154
|
+
fulfillerAddress,
|
|
155
|
+
orderHash,
|
|
156
|
+
protocolAddress,
|
|
157
|
+
this.chain,
|
|
158
|
+
assetContractAddress,
|
|
159
|
+
tokenId,
|
|
160
|
+
unitsToFill,
|
|
161
|
+
recipientAddress,
|
|
162
|
+
includeOptionalCreatorFees,
|
|
163
|
+
)
|
|
164
|
+
} else {
|
|
165
|
+
payload = getFulfillOfferPayload(
|
|
166
|
+
fulfillerAddress,
|
|
167
|
+
orderHash,
|
|
168
|
+
protocolAddress,
|
|
169
|
+
this.chain,
|
|
170
|
+
assetContractAddress,
|
|
171
|
+
tokenId,
|
|
172
|
+
unitsToFill,
|
|
173
|
+
includeOptionalCreatorFees,
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
const response = await this.fetcher.post<FulfillmentDataResponse>(
|
|
177
|
+
getFulfillmentDataPath(side),
|
|
178
|
+
payload,
|
|
179
|
+
)
|
|
180
|
+
return response
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Post an order to OpenSea.
|
|
185
|
+
* @deprecated Use postListing or postOffer instead.
|
|
186
|
+
*/
|
|
187
|
+
async postOrder(
|
|
188
|
+
order: ProtocolData,
|
|
189
|
+
apiOptions: OrderAPIOptions,
|
|
190
|
+
): Promise<OrderV2> {
|
|
191
|
+
const { protocol = "seaport", side, protocolAddress } = apiOptions
|
|
192
|
+
|
|
193
|
+
// Validate required fields
|
|
194
|
+
if (!side) {
|
|
195
|
+
throw new Error("apiOptions.side is required")
|
|
196
|
+
}
|
|
197
|
+
if (!protocolAddress) {
|
|
198
|
+
throw new Error("apiOptions.protocolAddress is required")
|
|
199
|
+
}
|
|
200
|
+
if (!order) {
|
|
201
|
+
throw new Error("order data is required")
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Validate protocol value
|
|
205
|
+
if (protocol !== "seaport") {
|
|
206
|
+
throw new Error("Currently only 'seaport' protocol is supported")
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Validate side value
|
|
210
|
+
if (side !== "ask" && side !== "bid") {
|
|
211
|
+
throw new Error("side must be either 'ask' or 'bid'")
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Validate protocolAddress format
|
|
215
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(protocolAddress)) {
|
|
216
|
+
throw new Error("Invalid protocol address format")
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const response = await this.fetcher.post<OrdersPostQueryResponse>(
|
|
220
|
+
getOrdersAPIPath(this.chain, protocol, side),
|
|
221
|
+
{ ...order, protocol_address: protocolAddress },
|
|
222
|
+
)
|
|
223
|
+
return deserializeOrder(response.order)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Post a listing to OpenSea. Returns the new Listing response format.
|
|
228
|
+
*/
|
|
229
|
+
async postListing(
|
|
230
|
+
order: ProtocolData,
|
|
231
|
+
protocolAddress: string,
|
|
232
|
+
): Promise<Listing> {
|
|
233
|
+
if (!order) {
|
|
234
|
+
throw new Error("order data is required")
|
|
235
|
+
}
|
|
236
|
+
if (!protocolAddress || !/^0x[a-fA-F0-9]{40}$/.test(protocolAddress)) {
|
|
237
|
+
throw new Error("Invalid protocol address format")
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const response = await this.fetcher.post<ListingPostQueryResponse>(
|
|
241
|
+
getOrdersAPIPath(this.chain, "seaport", OrderSide.LISTING),
|
|
242
|
+
{ ...order, protocol_address: protocolAddress },
|
|
243
|
+
)
|
|
244
|
+
return response.listing
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Post an offer to OpenSea. Returns the new Offer response format.
|
|
249
|
+
*/
|
|
250
|
+
async postOffer(
|
|
251
|
+
order: ProtocolData,
|
|
252
|
+
protocolAddress: string,
|
|
253
|
+
): Promise<Offer> {
|
|
254
|
+
if (!order) {
|
|
255
|
+
throw new Error("order data is required")
|
|
256
|
+
}
|
|
257
|
+
if (!protocolAddress || !/^0x[a-fA-F0-9]{40}$/.test(protocolAddress)) {
|
|
258
|
+
throw new Error("Invalid protocol address format")
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const response = await this.fetcher.post<OfferPostQueryResponse>(
|
|
262
|
+
getOrdersAPIPath(this.chain, "seaport", OrderSide.OFFER),
|
|
263
|
+
{ ...order, protocol_address: protocolAddress },
|
|
264
|
+
)
|
|
265
|
+
return response.offer
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
|
|
270
|
+
*/
|
|
271
|
+
async offchainCancelOrder(
|
|
272
|
+
protocolAddress: string,
|
|
273
|
+
orderHash: string,
|
|
274
|
+
chain: Chain = this.chain,
|
|
275
|
+
offererSignature?: string,
|
|
276
|
+
): Promise<CancelOrderResponse> {
|
|
277
|
+
const response = await this.fetcher.post<CancelOrderResponse>(
|
|
278
|
+
getCancelOrderPath(chain, protocolAddress, orderHash),
|
|
279
|
+
{ offererSignature },
|
|
280
|
+
)
|
|
281
|
+
return response
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getSearchPath } from "./apiPaths"
|
|
2
|
+
import type { Fetcher } from "./fetcher"
|
|
3
|
+
import type { SearchArgs, SearchResponse } from "./types"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Search-related API operations
|
|
7
|
+
*/
|
|
8
|
+
export class SearchAPI {
|
|
9
|
+
constructor(private fetcher: Fetcher) {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Search across collections, tokens, NFTs, and accounts.
|
|
13
|
+
*/
|
|
14
|
+
async search(args: SearchArgs): Promise<SearchResponse> {
|
|
15
|
+
const response = await this.fetcher.get<SearchResponse>(
|
|
16
|
+
getSearchPath(),
|
|
17
|
+
args,
|
|
18
|
+
)
|
|
19
|
+
return response
|
|
20
|
+
}
|
|
21
|
+
}
|