@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
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Seaport } from "@opensea/seaport-js";
|
|
2
|
+
import { ItemType } from "@opensea/seaport-js/lib/constants";
|
|
3
|
+
import type { TokenStandard } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Gets the appropriate ItemType for a given token standard.
|
|
6
|
+
* @param tokenStandard The token standard (ERC20, ERC721, ERC1155)
|
|
7
|
+
* @returns The corresponding ItemType from Seaport
|
|
8
|
+
*/
|
|
9
|
+
export declare const getAssetItemType: (tokenStandard: TokenStandard) => ItemType.ERC20 | ItemType.ERC721 | ItemType.ERC1155;
|
|
10
|
+
/**
|
|
11
|
+
* Remaps shared storefront token addresses to the lazy mint adapter address.
|
|
12
|
+
*
|
|
13
|
+
* OpenSea's shared storefront contracts require special handling - when a token
|
|
14
|
+
* is from a shared storefront address, it must be remapped to the lazy mint
|
|
15
|
+
* adapter address for proper Seaport order creation.
|
|
16
|
+
*
|
|
17
|
+
* @param tokenAddress The token contract address to check
|
|
18
|
+
* @returns The lazy mint adapter address if the input is a shared storefront address,
|
|
19
|
+
* otherwise returns the original address unchanged
|
|
20
|
+
*/
|
|
21
|
+
export declare const remapSharedStorefrontAddress: (tokenAddress: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Returns if a protocol address is valid.
|
|
24
|
+
* @param protocolAddress The protocol address
|
|
25
|
+
*/
|
|
26
|
+
export declare const isValidProtocol: (protocolAddress: string) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Throws an error if the protocol address is not valid.
|
|
29
|
+
* @param protocolAddress The protocol address
|
|
30
|
+
*/
|
|
31
|
+
export declare const requireValidProtocol: (protocolAddress: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Get the Seaport instance for a given protocol address.
|
|
34
|
+
* This is a shared utility to avoid duplicating the logic across multiple SDK manager classes.
|
|
35
|
+
* @param protocolAddress The protocol address
|
|
36
|
+
* @param seaport The Seaport instance
|
|
37
|
+
* @returns The Seaport instance for the given protocol address
|
|
38
|
+
* @throws Error if the protocol address is not supported
|
|
39
|
+
*/
|
|
40
|
+
export declare const getSeaportInstance: (protocolAddress: string, seaport: Seaport) => Seaport;
|
|
41
|
+
/**
|
|
42
|
+
* Get the Seaport version string for a given protocol address.
|
|
43
|
+
* @param protocolAddress The protocol address
|
|
44
|
+
* @returns The version string (e.g., "1.6")
|
|
45
|
+
* @throws Error if the protocol address is not supported
|
|
46
|
+
*/
|
|
47
|
+
export declare const getSeaportVersion: (protocolAddress: string) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Decodes an encoded string of token IDs into an array of individual token IDs using bigint for precise calculations.
|
|
50
|
+
*
|
|
51
|
+
* The encoded token IDs can be in the following formats:
|
|
52
|
+
* 1. Single numbers: '123' => ['123']
|
|
53
|
+
* 2. Comma-separated numbers: '1,2,3,4' => ['1', '2', '3', '4']
|
|
54
|
+
* 3. Ranges of numbers: '5:8' => ['5', '6', '7', '8']
|
|
55
|
+
* 4. Combinations of single numbers and ranges: '1,3:5,8' => ['1', '3', '4', '5', '8']
|
|
56
|
+
* 5. Wildcard '*' (matches all token IDs): '*' => ['*']
|
|
57
|
+
*
|
|
58
|
+
* @param encodedTokenIds - The encoded string of token IDs to be decoded.
|
|
59
|
+
* @returns An array of individual token IDs after decoding the input.
|
|
60
|
+
*
|
|
61
|
+
* @throws {Error} If the input is not correctly formatted or if bigint operations fail.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const encoded = '1,3:5,8';
|
|
65
|
+
* const decoded = decodeTokenIds(encoded); // Output: ['1', '3', '4', '5', '8']
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const encodedWildcard = '*';
|
|
69
|
+
* const decodedWildcard = decodeTokenIds(encodedWildcard); // Output: ['*']
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const emptyEncoded = '';
|
|
73
|
+
* const decodedEmpty = decodeTokenIds(emptyEncoded); // Output: []
|
|
74
|
+
*/
|
|
75
|
+
export declare const decodeTokenIds: (encodedTokenIds: string) => string[];
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeTokenIds = exports.getSeaportVersion = exports.getSeaportInstance = exports.requireValidProtocol = exports.isValidProtocol = exports.remapSharedStorefrontAddress = exports.getAssetItemType = void 0;
|
|
4
|
+
const constants_1 = require("@opensea/seaport-js/lib/constants");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const constants_2 = require("../constants");
|
|
7
|
+
// Pre-compute checksummed protocol addresses for consistent comparisons
|
|
8
|
+
const VALID_PROTOCOL_ADDRESSES = new Set([
|
|
9
|
+
ethers_1.ethers.getAddress(constants_1.CROSS_CHAIN_SEAPORT_V1_6_ADDRESS),
|
|
10
|
+
ethers_1.ethers.getAddress(constants_2.ALTERNATE_SEAPORT_V1_6_ADDRESS),
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* Gets the appropriate ItemType for a given token standard.
|
|
14
|
+
* @param tokenStandard The token standard (ERC20, ERC721, ERC1155)
|
|
15
|
+
* @returns The corresponding ItemType from Seaport
|
|
16
|
+
*/
|
|
17
|
+
const getAssetItemType = (tokenStandard) => {
|
|
18
|
+
const normalizedStandard = tokenStandard.toUpperCase();
|
|
19
|
+
switch (normalizedStandard) {
|
|
20
|
+
case "ERC20":
|
|
21
|
+
return constants_1.ItemType.ERC20;
|
|
22
|
+
case "ERC721":
|
|
23
|
+
return constants_1.ItemType.ERC721;
|
|
24
|
+
case "ERC1155":
|
|
25
|
+
return constants_1.ItemType.ERC1155;
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`Unknown schema name: ${tokenStandard}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.getAssetItemType = getAssetItemType;
|
|
31
|
+
/**
|
|
32
|
+
* Remaps shared storefront token addresses to the lazy mint adapter address.
|
|
33
|
+
*
|
|
34
|
+
* OpenSea's shared storefront contracts require special handling - when a token
|
|
35
|
+
* is from a shared storefront address, it must be remapped to the lazy mint
|
|
36
|
+
* adapter address for proper Seaport order creation.
|
|
37
|
+
*
|
|
38
|
+
* @param tokenAddress The token contract address to check
|
|
39
|
+
* @returns The lazy mint adapter address if the input is a shared storefront address,
|
|
40
|
+
* otherwise returns the original address unchanged
|
|
41
|
+
*/
|
|
42
|
+
const remapSharedStorefrontAddress = (tokenAddress) => {
|
|
43
|
+
if (constants_2.SHARED_STOREFRONT_ADDRESSES.has(tokenAddress.toLowerCase())) {
|
|
44
|
+
return ethers_1.ethers.getAddress(constants_2.SHARED_STOREFRONT_LAZY_MINT_ADAPTER_CROSS_CHAIN_ADDRESS);
|
|
45
|
+
}
|
|
46
|
+
return tokenAddress;
|
|
47
|
+
};
|
|
48
|
+
exports.remapSharedStorefrontAddress = remapSharedStorefrontAddress;
|
|
49
|
+
/**
|
|
50
|
+
* Returns if a protocol address is valid.
|
|
51
|
+
* @param protocolAddress The protocol address
|
|
52
|
+
*/
|
|
53
|
+
const isValidProtocol = (protocolAddress) => {
|
|
54
|
+
try {
|
|
55
|
+
return VALID_PROTOCOL_ADDRESSES.has(ethers_1.ethers.getAddress(protocolAddress));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.isValidProtocol = isValidProtocol;
|
|
62
|
+
/**
|
|
63
|
+
* Throws an error if the protocol address is not valid.
|
|
64
|
+
* @param protocolAddress The protocol address
|
|
65
|
+
*/
|
|
66
|
+
const requireValidProtocol = (protocolAddress) => {
|
|
67
|
+
if (!(0, exports.isValidProtocol)(protocolAddress)) {
|
|
68
|
+
throw new Error(`Unsupported protocol address: ${protocolAddress}`);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.requireValidProtocol = requireValidProtocol;
|
|
72
|
+
/**
|
|
73
|
+
* Get the Seaport instance for a given protocol address.
|
|
74
|
+
* This is a shared utility to avoid duplicating the logic across multiple SDK manager classes.
|
|
75
|
+
* @param protocolAddress The protocol address
|
|
76
|
+
* @param seaport The Seaport instance
|
|
77
|
+
* @returns The Seaport instance for the given protocol address
|
|
78
|
+
* @throws Error if the protocol address is not supported
|
|
79
|
+
*/
|
|
80
|
+
const getSeaportInstance = (protocolAddress, seaport) => {
|
|
81
|
+
(0, exports.requireValidProtocol)(protocolAddress);
|
|
82
|
+
return seaport;
|
|
83
|
+
};
|
|
84
|
+
exports.getSeaportInstance = getSeaportInstance;
|
|
85
|
+
/**
|
|
86
|
+
* Get the Seaport version string for a given protocol address.
|
|
87
|
+
* @param protocolAddress The protocol address
|
|
88
|
+
* @returns The version string (e.g., "1.6")
|
|
89
|
+
* @throws Error if the protocol address is not supported
|
|
90
|
+
*/
|
|
91
|
+
const getSeaportVersion = (protocolAddress) => {
|
|
92
|
+
(0, exports.requireValidProtocol)(protocolAddress);
|
|
93
|
+
return "1.6";
|
|
94
|
+
};
|
|
95
|
+
exports.getSeaportVersion = getSeaportVersion;
|
|
96
|
+
/**
|
|
97
|
+
* Decodes an encoded string of token IDs into an array of individual token IDs using bigint for precise calculations.
|
|
98
|
+
*
|
|
99
|
+
* The encoded token IDs can be in the following formats:
|
|
100
|
+
* 1. Single numbers: '123' => ['123']
|
|
101
|
+
* 2. Comma-separated numbers: '1,2,3,4' => ['1', '2', '3', '4']
|
|
102
|
+
* 3. Ranges of numbers: '5:8' => ['5', '6', '7', '8']
|
|
103
|
+
* 4. Combinations of single numbers and ranges: '1,3:5,8' => ['1', '3', '4', '5', '8']
|
|
104
|
+
* 5. Wildcard '*' (matches all token IDs): '*' => ['*']
|
|
105
|
+
*
|
|
106
|
+
* @param encodedTokenIds - The encoded string of token IDs to be decoded.
|
|
107
|
+
* @returns An array of individual token IDs after decoding the input.
|
|
108
|
+
*
|
|
109
|
+
* @throws {Error} If the input is not correctly formatted or if bigint operations fail.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* const encoded = '1,3:5,8';
|
|
113
|
+
* const decoded = decodeTokenIds(encoded); // Output: ['1', '3', '4', '5', '8']
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const encodedWildcard = '*';
|
|
117
|
+
* const decodedWildcard = decodeTokenIds(encodedWildcard); // Output: ['*']
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* const emptyEncoded = '';
|
|
121
|
+
* const decodedEmpty = decodeTokenIds(emptyEncoded); // Output: []
|
|
122
|
+
*/
|
|
123
|
+
const decodeTokenIds = (encodedTokenIds) => {
|
|
124
|
+
if (encodedTokenIds === "*") {
|
|
125
|
+
return ["*"];
|
|
126
|
+
}
|
|
127
|
+
if (encodedTokenIds === "") {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
// Check for whitespace and provide helpful error message
|
|
131
|
+
if (/\s/.test(encodedTokenIds)) {
|
|
132
|
+
throw new Error("Invalid input format: whitespace is not allowed. Expected format: '1,2,3' or '1:5' or '1,3:5,8' (no spaces).");
|
|
133
|
+
}
|
|
134
|
+
const validFormatRegex = /^(\d+(:\d+)?)(,\d+(:\d+)?)*$/;
|
|
135
|
+
if (!validFormatRegex.test(encodedTokenIds)) {
|
|
136
|
+
throw new Error("Invalid input format. Expected a valid comma-separated list of numbers and ranges.");
|
|
137
|
+
}
|
|
138
|
+
const ranges = encodedTokenIds.split(",");
|
|
139
|
+
const tokenIds = [];
|
|
140
|
+
for (const range of ranges) {
|
|
141
|
+
if (range.includes(":")) {
|
|
142
|
+
const [startStr, endStr] = range.split(":");
|
|
143
|
+
const start = BigInt(startStr);
|
|
144
|
+
const end = BigInt(endStr);
|
|
145
|
+
const diff = end - start + 1n;
|
|
146
|
+
if (diff <= 0) {
|
|
147
|
+
throw new Error(`Invalid range. End value: ${end} must be greater than or equal to the start value: ${start}.`);
|
|
148
|
+
}
|
|
149
|
+
for (let i = 0n; i < diff; i += 1n) {
|
|
150
|
+
tokenIds.push((start + i).toString());
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const tokenId = BigInt(range);
|
|
155
|
+
tokenIds.push(tokenId.toString());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return tokenIds;
|
|
159
|
+
};
|
|
160
|
+
exports.decodeTokenIds = decodeTokenIds;
|
|
161
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/utils/protocol.ts"],"names":[],"mappings":";;;AACA,iEAG0C;AAC1C,mCAA+B;AAC/B,4CAIqB;AAGrB,wEAAwE;AACxE,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACvC,eAAM,CAAC,UAAU,CAAC,4CAAgC,CAAC;IACnD,eAAM,CAAC,UAAU,CAAC,0CAA8B,CAAC;CAClD,CAAC,CAAA;AAEF;;;;GAIG;AACI,MAAM,gBAAgB,GAAG,CAAC,aAA4B,EAAE,EAAE;IAC/D,MAAM,kBAAkB,GAAG,aAAa,CAAC,WAAW,EAAE,CAAA;IACtD,QAAQ,kBAAkB,EAAE,CAAC;QAC3B,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M,IAAI,GAAG,GAAG,GAAG,KAAK,GAAG,EAAE,CAAA;YAE7B,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CACb,6BAA6B,GAAG,sDAAsD,KAAK,GAAG,CAC/F,CAAA;YACH,CAAC;YAED,KAAK,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;gBACnC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;YAC7B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAlDY,QAAA,cAAc,kBAkD1B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for handling rate-limited operations with retries.
|
|
3
|
+
* This is exported for SDK consumers who may want to use executeWithRateLimit
|
|
4
|
+
* for their own OpenSea API integrations.
|
|
5
|
+
*/
|
|
6
|
+
export interface RateLimitOptions {
|
|
7
|
+
/** Logger function for logging progress */
|
|
8
|
+
logger?: (message: string) => void;
|
|
9
|
+
/** Maximum number of retry attempts for rate limit errors */
|
|
10
|
+
maxRetries?: number;
|
|
11
|
+
/** Base delay in ms to wait after a rate limit error if retry-after header is not present */
|
|
12
|
+
baseRetryDelay?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Execute an async operation with automatic retry on rate limit errors.
|
|
16
|
+
* Respects the retry-after header when present, otherwise uses exponential backoff.
|
|
17
|
+
*
|
|
18
|
+
* @param operation The async operation to execute
|
|
19
|
+
* @param options Configuration for rate limit handling
|
|
20
|
+
* @returns The result of the operation
|
|
21
|
+
* @throws The last error encountered if all retries are exhausted
|
|
22
|
+
*/
|
|
23
|
+
export declare function executeWithRateLimit<T>(operation: () => Promise<T>, options?: RateLimitOptions): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Execute an array of async operations sequentially with rate limit handling.
|
|
26
|
+
* Logs progress after each operation.
|
|
27
|
+
*
|
|
28
|
+
* @param operations Array of async operations to execute
|
|
29
|
+
* @param options Configuration for rate limit handling and progress logging
|
|
30
|
+
* @returns Array of results from each operation
|
|
31
|
+
*/
|
|
32
|
+
export declare function executeSequentialWithRateLimit<T>(operations: Array<() => Promise<T>>, options?: RateLimitOptions & {
|
|
33
|
+
operationName?: string;
|
|
34
|
+
}): Promise<T[]>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeWithRateLimit = executeWithRateLimit;
|
|
4
|
+
exports.executeSequentialWithRateLimit = executeSequentialWithRateLimit;
|
|
5
|
+
const stringHelper_1 = require("./stringHelper");
|
|
6
|
+
/**
|
|
7
|
+
* Default configuration for rate limit handling
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
10
|
+
const DEFAULT_BASE_RETRY_DELAY_MS = 1000;
|
|
11
|
+
const EXPONENTIAL_BACKOFF_BASE = 2;
|
|
12
|
+
const MILLISECONDS_PER_SECOND = 1000;
|
|
13
|
+
/**
|
|
14
|
+
* HTTP status codes that indicate rate limiting
|
|
15
|
+
*/
|
|
16
|
+
const RATE_LIMIT_STATUS_CODE = 429;
|
|
17
|
+
const CUSTOM_RATE_LIMIT_STATUS_CODE = 599;
|
|
18
|
+
/**
|
|
19
|
+
* Sleep for a specified duration
|
|
20
|
+
* @param ms Duration in milliseconds
|
|
21
|
+
*/
|
|
22
|
+
function sleep(ms) {
|
|
23
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Execute an async operation with automatic retry on rate limit errors.
|
|
27
|
+
* Respects the retry-after header when present, otherwise uses exponential backoff.
|
|
28
|
+
*
|
|
29
|
+
* @param operation The async operation to execute
|
|
30
|
+
* @param options Configuration for rate limit handling
|
|
31
|
+
* @returns The result of the operation
|
|
32
|
+
* @throws The last error encountered if all retries are exhausted
|
|
33
|
+
*/
|
|
34
|
+
async function executeWithRateLimit(operation, options = {}) {
|
|
35
|
+
const { logger = () => { }, maxRetries = DEFAULT_MAX_RETRIES, baseRetryDelay = DEFAULT_BASE_RETRY_DELAY_MS, } = options;
|
|
36
|
+
let lastError;
|
|
37
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
38
|
+
try {
|
|
39
|
+
return await operation();
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
lastError = error;
|
|
43
|
+
const rateLimitError = error;
|
|
44
|
+
// Check if this is a rate limit error by status code (robust) or retry-after header
|
|
45
|
+
const isRateLimitError = rateLimitError.statusCode === RATE_LIMIT_STATUS_CODE ||
|
|
46
|
+
rateLimitError.statusCode === CUSTOM_RATE_LIMIT_STATUS_CODE ||
|
|
47
|
+
rateLimitError.retryAfter !== undefined;
|
|
48
|
+
if (!isRateLimitError || attempt === maxRetries) {
|
|
49
|
+
// Not a rate limit error or out of retries, throw the error
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
// Calculate delay
|
|
53
|
+
let delayMs;
|
|
54
|
+
if (rateLimitError.retryAfter !== undefined) {
|
|
55
|
+
delayMs = rateLimitError.retryAfter * MILLISECONDS_PER_SECOND;
|
|
56
|
+
logger(`Rate limit hit. Waiting ${rateLimitError.retryAfter} seconds before retry (attempt ${attempt + 1}/${maxRetries})...`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// Exponential backoff
|
|
60
|
+
delayMs = baseRetryDelay * EXPONENTIAL_BACKOFF_BASE ** attempt;
|
|
61
|
+
const delaySeconds = delayMs / MILLISECONDS_PER_SECOND;
|
|
62
|
+
logger(`Rate limit hit. Waiting ${delaySeconds} seconds before retry (attempt ${attempt + 1}/${maxRetries})...`);
|
|
63
|
+
}
|
|
64
|
+
await sleep(delayMs);
|
|
65
|
+
logger(`Retrying operation...`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Should never reach here, but TypeScript needs this
|
|
69
|
+
throw lastError;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Execute an array of async operations sequentially with rate limit handling.
|
|
73
|
+
* Logs progress after each operation.
|
|
74
|
+
*
|
|
75
|
+
* @param operations Array of async operations to execute
|
|
76
|
+
* @param options Configuration for rate limit handling and progress logging
|
|
77
|
+
* @returns Array of results from each operation
|
|
78
|
+
*/
|
|
79
|
+
async function executeSequentialWithRateLimit(operations, options = {}) {
|
|
80
|
+
const { logger = () => { }, operationName = "operation", ...rateLimitOptions } = options;
|
|
81
|
+
const results = [];
|
|
82
|
+
const total = operations.length;
|
|
83
|
+
logger(`Starting ${total} ${(0, stringHelper_1.pluralize)(total, operationName)}...`);
|
|
84
|
+
for (let i = 0; i < operations.length; i++) {
|
|
85
|
+
const operation = operations[i];
|
|
86
|
+
logger(`Executing ${operationName} ${i + 1}/${total}...`);
|
|
87
|
+
const result = await executeWithRateLimit(operation, {
|
|
88
|
+
...rateLimitOptions,
|
|
89
|
+
logger,
|
|
90
|
+
});
|
|
91
|
+
results.push(result);
|
|
92
|
+
logger(`Completed ${operationName} ${i + 1}/${total}`);
|
|
93
|
+
}
|
|
94
|
+
logger(`All ${total} ${(0, stringHelper_1.pluralize)(total, operationName)} completed successfully`);
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=rateLimit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimit.js","sourceRoot":"","sources":["../../src/utils/rateLimit.ts"],"names":[],"mappings":";;AAgDA,oDAqDC;AAUD,wEAmCC;AAjJD,iDAA0C;AAE1C;;G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,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,SAAS,EAAE;YACnD,GAAG,gBAAgB;YACnB,MAAM;SACP,CAAC,CAAA;QAEF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACpB,MAAM,CAAC,aAAa,aAAa,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,CACJ,OAAO,KAAK,IAAI,IAAA,wBAAS,EAAC,KAAK,EAAE,aAAa,CAAC,yBAAyB,CACzE,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for string formatting and manipulation.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Pluralizes a word based on count.
|
|
6
|
+
*
|
|
7
|
+
* @param count The number of items
|
|
8
|
+
* @param singular The singular form of the word
|
|
9
|
+
* @param plural Optional custom plural form. If not provided, adds 's' to singular
|
|
10
|
+
* @returns The appropriately pluralized word
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* pluralize(1, 'listing') // 'listing'
|
|
14
|
+
* pluralize(5, 'listing') // 'listings'
|
|
15
|
+
* pluralize(1, 'query', 'queries') // 'query'
|
|
16
|
+
* pluralize(3, 'query', 'queries') // 'queries'
|
|
17
|
+
*/
|
|
18
|
+
export declare function pluralize(count: number, singular: string, plural?: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for string formatting and manipulation.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pluralize = pluralize;
|
|
7
|
+
/**
|
|
8
|
+
* Pluralizes a word based on count.
|
|
9
|
+
*
|
|
10
|
+
* @param count The number of items
|
|
11
|
+
* @param singular The singular form of the word
|
|
12
|
+
* @param plural Optional custom plural form. If not provided, adds 's' to singular
|
|
13
|
+
* @returns The appropriately pluralized word
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* pluralize(1, 'listing') // 'listing'
|
|
17
|
+
* pluralize(5, 'listing') // 'listings'
|
|
18
|
+
* pluralize(1, 'query', 'queries') // 'query'
|
|
19
|
+
* pluralize(3, 'query', 'queries') // 'queries'
|
|
20
|
+
*/
|
|
21
|
+
function pluralize(count, singular, plural) {
|
|
22
|
+
return count === 1 ? singular : plural || `${singular}s`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=stringHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringHelper.js","sourceRoot":"","sources":["../../src/utils/stringHelper.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAgBH,8BAMC;AApBD;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACvB,KAAa,EACb,QAAgB,EAChB,MAAe;IAEf,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ethers } from "ethers";
|
|
2
|
+
export * from "./chain";
|
|
3
|
+
export * from "./converters";
|
|
4
|
+
export * from "./fees";
|
|
5
|
+
export * from "./protocol";
|
|
6
|
+
/**
|
|
7
|
+
* Estimate gas usage for a transaction.
|
|
8
|
+
* @param provider The Provider
|
|
9
|
+
* @param from Address sending transaction
|
|
10
|
+
* @param to Destination contract address
|
|
11
|
+
* @param data Data to send to contract
|
|
12
|
+
* @param value Value in ETH to send with data
|
|
13
|
+
*/
|
|
14
|
+
export declare function estimateGas(provider: ethers.Provider, { from, to, data, value }: ethers.Transaction): Promise<bigint>;
|
|
15
|
+
interface ErrorWithCode extends Error {
|
|
16
|
+
code: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const hasErrorCode: (error: unknown) => error is ErrorWithCode;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.hasErrorCode = void 0;
|
|
18
|
+
exports.estimateGas = estimateGas;
|
|
19
|
+
__exportStar(require("./chain"), exports);
|
|
20
|
+
// Re-export all utilities from specialized modules
|
|
21
|
+
__exportStar(require("./converters"), exports);
|
|
22
|
+
__exportStar(require("./fees"), exports);
|
|
23
|
+
__exportStar(require("./protocol"), exports);
|
|
24
|
+
/**
|
|
25
|
+
* Estimate gas usage for a transaction.
|
|
26
|
+
* @param provider The Provider
|
|
27
|
+
* @param from Address sending transaction
|
|
28
|
+
* @param to Destination contract address
|
|
29
|
+
* @param data Data to send to contract
|
|
30
|
+
* @param value Value in ETH to send with data
|
|
31
|
+
*/
|
|
32
|
+
async function estimateGas(provider, { from, to, data, value = 0n }) {
|
|
33
|
+
return await provider.estimateGas({
|
|
34
|
+
from,
|
|
35
|
+
to,
|
|
36
|
+
value: value.toString(),
|
|
37
|
+
data,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const hasErrorCode = (error) => {
|
|
41
|
+
const untypedError = error;
|
|
42
|
+
return !!untypedError.code;
|
|
43
|
+
};
|
|
44
|
+
exports.hasErrorCode = hasErrorCode;
|
|
45
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAgBA,kCAUC;AAxBD,0CAAuB;AACvB,mDAAmD;AACnD,+CAA4B;AAC5B,yCAAsB;AACtB,6CAA0B;AAE1B;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,QAAyB,EACzB,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,GAAG,EAAE,EAAsB;IAElD,OAAO,MAAM,QAAQ,CAAC,WAAW,CAAC;QAChC,IAAI;QACJ,EAAE;QACF,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;QACvB,IAAI;KACL,CAAC,CAAA;AACJ,CAAC;AAMM,MAAM,YAAY,GAAG,CAAC,KAAc,EAA0B,EAAE;IACrE,MAAM,YAAY,GAAG,KAA+B,CAAA;IACpD,OAAO,CAAC,CAAC,YAAY,CAAC,IAAI,CAAA;AAC5B,CAAC,CAAA;AAHY,QAAA,YAAY,gBAGxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opensea/sdk",
|
|
3
|
+
"version": "9.0.0",
|
|
4
|
+
"description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "OpenSea Developers",
|
|
7
|
+
"homepage": "https://docs.opensea.io/reference/api-overview",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/ProjectOpenSea/opensea-js.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ProjectOpenSea/opensea-js/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"main": "lib/index.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"abi-type-gen": "typechain --target=ethers-v6 src/abi/*.json --out-dir=src/typechain/contracts",
|
|
23
|
+
"build": "npm run abi-type-gen && tsc -p tsconfig.build.json",
|
|
24
|
+
"check-types": "tsc --noEmit --project tsconfig.json",
|
|
25
|
+
"docs-build": "typedoc",
|
|
26
|
+
"docs-build-md": "typedoc --plugin typedoc-plugin-markdown",
|
|
27
|
+
"format": "biome format --config-path ../.. --write .",
|
|
28
|
+
"format:check": "biome format --config-path ../.. .",
|
|
29
|
+
"lint": "concurrently \"npm run check-types\" \"biome check --config-path ../.. .\"",
|
|
30
|
+
"lint:fix": "biome check --config-path ../.. --write .",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:all": "concurrently \"npm run test\" \"npm run test:integration\"",
|
|
33
|
+
"test:coverage": "vitest run --coverage",
|
|
34
|
+
"test:integration": "vitest run --config vitest.integration.config.ts"
|
|
35
|
+
},
|
|
36
|
+
"types": "lib/index.d.ts",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@opensea/api-types": "workspace:^",
|
|
39
|
+
"@opensea/seaport-js": "^4.0.7",
|
|
40
|
+
"ethers": "^6.16.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@typechain/ethers-v6": "^0.5.1",
|
|
44
|
+
"@types/node": "^25.4.0",
|
|
45
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
46
|
+
"concurrently": "^9.2.1",
|
|
47
|
+
"dotenv": "^17.3.1",
|
|
48
|
+
"typechain": "^8.0.0",
|
|
49
|
+
"typedoc": "^0.28.17",
|
|
50
|
+
"typedoc-plugin-markdown": "^4.10.0",
|
|
51
|
+
"typescript": "^6.0.2",
|
|
52
|
+
"typescript-eslint": "^8.57.0",
|
|
53
|
+
"vitest": "^3.2.4"
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"collectibles",
|
|
57
|
+
"crypto",
|
|
58
|
+
"ethereum",
|
|
59
|
+
"javascript",
|
|
60
|
+
"marketplace",
|
|
61
|
+
"nft",
|
|
62
|
+
"node",
|
|
63
|
+
"non-fungible tokens",
|
|
64
|
+
"opensea",
|
|
65
|
+
"sdk",
|
|
66
|
+
"smart contracts",
|
|
67
|
+
"typescript"
|
|
68
|
+
],
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=20.0.0"
|
|
71
|
+
}
|
|
72
|
+
}
|