@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,145 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Fee,
|
|
3
|
+
OpenSeaAccount,
|
|
4
|
+
OpenSeaCollection,
|
|
5
|
+
OpenSeaPaymentToken,
|
|
6
|
+
PricingCurrencies,
|
|
7
|
+
RarityStrategy,
|
|
8
|
+
} from "../types"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Converts a collection JSON response to an OpenSeaCollection object.
|
|
12
|
+
* @param collection The raw collection JSON from the API
|
|
13
|
+
* @returns OpenSeaCollection object
|
|
14
|
+
*/
|
|
15
|
+
export const collectionFromJSON = (collection: any): OpenSeaCollection => {
|
|
16
|
+
return {
|
|
17
|
+
name: collection.name,
|
|
18
|
+
collection: collection.collection,
|
|
19
|
+
description: collection.description,
|
|
20
|
+
imageUrl: collection.image_url,
|
|
21
|
+
bannerImageUrl: collection.banner_image_url,
|
|
22
|
+
owner: collection.owner,
|
|
23
|
+
safelistStatus: collection.safelist_status,
|
|
24
|
+
category: collection.category,
|
|
25
|
+
isDisabled: collection.is_disabled,
|
|
26
|
+
isNSFW: collection.is_nsfw,
|
|
27
|
+
traitOffersEnabled: collection.trait_offers_enabled,
|
|
28
|
+
collectionOffersEnabled: collection.collection_offers_enabled,
|
|
29
|
+
openseaUrl: collection.opensea_url,
|
|
30
|
+
projectUrl: collection.project_url,
|
|
31
|
+
wikiUrl: collection.wiki_url,
|
|
32
|
+
discordUrl: collection.discord_url,
|
|
33
|
+
telegramUrl: collection.telegram_url,
|
|
34
|
+
twitterUsername: collection.twitter_username,
|
|
35
|
+
instagramUsername: collection.instagram_username,
|
|
36
|
+
contracts: (collection.contracts ?? []).map((contract: any) => ({
|
|
37
|
+
address: contract.address,
|
|
38
|
+
chain: contract.chain,
|
|
39
|
+
})),
|
|
40
|
+
editors: collection.editors,
|
|
41
|
+
fees: (collection.fees ?? []).map(feeFromJSON),
|
|
42
|
+
rarity: rarityFromJSON(collection.rarity),
|
|
43
|
+
pricingCurrencies: pricingCurrenciesFromJSON(collection.pricing_currencies),
|
|
44
|
+
totalSupply: collection.total_supply,
|
|
45
|
+
uniqueItemCount: collection.unique_item_count,
|
|
46
|
+
createdDate: collection.created_date,
|
|
47
|
+
requiredZone: collection.required_zone,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Converts a rarity JSON response to a RarityStrategy object.
|
|
53
|
+
* @param rarity The raw rarity JSON from the API
|
|
54
|
+
* @returns RarityStrategy object or null
|
|
55
|
+
*/
|
|
56
|
+
export const rarityFromJSON = (rarity: any): RarityStrategy | null => {
|
|
57
|
+
if (!rarity) {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
const fromJSON: RarityStrategy = {
|
|
61
|
+
strategyId: rarity.strategy_id,
|
|
62
|
+
strategyVersion: rarity.strategy_version,
|
|
63
|
+
calculatedAt: rarity.calculated_at,
|
|
64
|
+
maxRank: rarity.max_rank,
|
|
65
|
+
tokensScored: rarity.tokens_scored,
|
|
66
|
+
}
|
|
67
|
+
return fromJSON
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Converts a payment token JSON response to an OpenSeaPaymentToken object.
|
|
72
|
+
* @param token The raw payment token JSON from the API
|
|
73
|
+
* @returns OpenSeaPaymentToken object
|
|
74
|
+
*/
|
|
75
|
+
export const paymentTokenFromJSON = (token: any): OpenSeaPaymentToken => {
|
|
76
|
+
const fromJSON: OpenSeaPaymentToken = {
|
|
77
|
+
name: token.name,
|
|
78
|
+
symbol: token.symbol,
|
|
79
|
+
decimals: token.decimals,
|
|
80
|
+
address: token.address,
|
|
81
|
+
chain: token.chain,
|
|
82
|
+
imageUrl: token.image,
|
|
83
|
+
ethPrice: token.eth_price,
|
|
84
|
+
usdPrice: token.usd_price,
|
|
85
|
+
}
|
|
86
|
+
return fromJSON
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Converts a pricing currencies JSON response to a PricingCurrencies object.
|
|
91
|
+
* @param pricingCurrencies The raw pricing currencies JSON from the API
|
|
92
|
+
* @returns PricingCurrencies object or undefined
|
|
93
|
+
*/
|
|
94
|
+
export const pricingCurrenciesFromJSON = (
|
|
95
|
+
pricingCurrencies: any,
|
|
96
|
+
): PricingCurrencies | undefined => {
|
|
97
|
+
if (!pricingCurrencies) {
|
|
98
|
+
return undefined
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
listingCurrency: pricingCurrencies.listing_currency
|
|
102
|
+
? paymentTokenFromJSON(pricingCurrencies.listing_currency)
|
|
103
|
+
: undefined,
|
|
104
|
+
offerCurrency: pricingCurrencies.offer_currency
|
|
105
|
+
? paymentTokenFromJSON(pricingCurrencies.offer_currency)
|
|
106
|
+
: undefined,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Converts an account JSON response to an OpenSeaAccount object.
|
|
112
|
+
* @param account The raw account JSON from the API
|
|
113
|
+
* @returns OpenSeaAccount object
|
|
114
|
+
*/
|
|
115
|
+
export const accountFromJSON = (account: any): OpenSeaAccount => {
|
|
116
|
+
return {
|
|
117
|
+
address: account.address,
|
|
118
|
+
username: account.username,
|
|
119
|
+
profileImageUrl: account.profile_image_url,
|
|
120
|
+
bannerImageUrl: account.banner_image_url,
|
|
121
|
+
website: account.website,
|
|
122
|
+
socialMediaAccounts: (account.social_media_accounts ?? []).map(
|
|
123
|
+
(acct: any) => ({
|
|
124
|
+
platform: acct.platform,
|
|
125
|
+
username: acct.username,
|
|
126
|
+
}),
|
|
127
|
+
),
|
|
128
|
+
bio: account.bio,
|
|
129
|
+
joinedDate: account.joined_date,
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Converts a fee JSON response to a Fee object.
|
|
135
|
+
* @param fee The raw fee JSON from the API
|
|
136
|
+
* @returns Fee object
|
|
137
|
+
*/
|
|
138
|
+
export const feeFromJSON = (fee: any): Fee => {
|
|
139
|
+
const fromJSON: Fee = {
|
|
140
|
+
fee: fee.fee,
|
|
141
|
+
recipient: fee.recipient,
|
|
142
|
+
required: fee.required,
|
|
143
|
+
}
|
|
144
|
+
return fromJSON
|
|
145
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with Unix timestamps (seconds since epoch).
|
|
3
|
+
* OpenSea API and Seaport protocol use Unix timestamps in seconds, not milliseconds.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the current Unix timestamp in seconds
|
|
8
|
+
* @returns Current time as Unix timestamp (seconds since epoch)
|
|
9
|
+
*/
|
|
10
|
+
export function getCurrentUnixTimestamp(): number {
|
|
11
|
+
return Math.floor(Date.now() / 1000)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get a Unix timestamp for a future time
|
|
16
|
+
* @param seconds Number of seconds from now
|
|
17
|
+
* @returns Unix timestamp (seconds since epoch)
|
|
18
|
+
* @example
|
|
19
|
+
* // Get timestamp for 1 day from now
|
|
20
|
+
* const tomorrow = getUnixTimestampInSeconds(60 * 60 * 24);
|
|
21
|
+
*/
|
|
22
|
+
export function getUnixTimestampInSeconds(seconds: number): number {
|
|
23
|
+
return getCurrentUnixTimestamp() + seconds
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Common time durations in seconds for convenience
|
|
28
|
+
*/
|
|
29
|
+
export enum TimeInSeconds {
|
|
30
|
+
/** 1 minute = 60 seconds */
|
|
31
|
+
MINUTE = 60,
|
|
32
|
+
/** 1 hour = 3600 seconds */
|
|
33
|
+
HOUR = 3600,
|
|
34
|
+
/** 1 day = 86400 seconds */
|
|
35
|
+
DAY = 86400,
|
|
36
|
+
/** 1 week = 604800 seconds */
|
|
37
|
+
WEEK = 604800,
|
|
38
|
+
/** 30 days = 2592000 seconds */
|
|
39
|
+
MONTH = 2592000,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get Unix timestamp for one month from now (30 days)
|
|
44
|
+
* @returns Unix timestamp (seconds since epoch) for 30 days in the future
|
|
45
|
+
*/
|
|
46
|
+
export const oneMonthFromNowInSeconds = (): number => {
|
|
47
|
+
return getUnixTimestampInSeconds(TimeInSeconds.MONTH)
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FixedNumber } from "ethers"
|
|
2
|
+
import { FIXED_NUMBER_100 } from "../constants"
|
|
3
|
+
import type { Fee } from "../types"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sums up the basis points for fees.
|
|
7
|
+
* @param fees The fees to sum up
|
|
8
|
+
* @returns sum of basis points
|
|
9
|
+
*/
|
|
10
|
+
export const totalBasisPointsForFees = (fees: Fee[]): bigint => {
|
|
11
|
+
const feeBasisPoints = fees.map(fee => basisPointsForFee(fee))
|
|
12
|
+
const totalBasisPoints = feeBasisPoints.reduce(
|
|
13
|
+
(sum, basisPoints) => basisPoints + sum,
|
|
14
|
+
0n,
|
|
15
|
+
)
|
|
16
|
+
return totalBasisPoints
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Converts a fee to its basis points representation.
|
|
21
|
+
* @param fee The fee to convert
|
|
22
|
+
* @returns the basis points
|
|
23
|
+
*/
|
|
24
|
+
export const basisPointsForFee = (fee: Fee): bigint => {
|
|
25
|
+
return BigInt(
|
|
26
|
+
FixedNumber.fromString(fee.fee.toString())
|
|
27
|
+
.mul(FIXED_NUMBER_100)
|
|
28
|
+
.toFormat(0) // format to 0 decimal places to convert to bigint
|
|
29
|
+
.toString(),
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { Seaport } from "@opensea/seaport-js"
|
|
2
|
+
import {
|
|
3
|
+
CROSS_CHAIN_SEAPORT_V1_6_ADDRESS,
|
|
4
|
+
ItemType,
|
|
5
|
+
} from "@opensea/seaport-js/lib/constants"
|
|
6
|
+
import { ethers } from "ethers"
|
|
7
|
+
import {
|
|
8
|
+
ALTERNATE_SEAPORT_V1_6_ADDRESS,
|
|
9
|
+
SHARED_STOREFRONT_ADDRESSES,
|
|
10
|
+
SHARED_STOREFRONT_LAZY_MINT_ADAPTER_CROSS_CHAIN_ADDRESS,
|
|
11
|
+
} from "../constants"
|
|
12
|
+
import type { TokenStandard } from "../types"
|
|
13
|
+
|
|
14
|
+
// Pre-compute checksummed protocol addresses for consistent comparisons
|
|
15
|
+
const VALID_PROTOCOL_ADDRESSES = new Set([
|
|
16
|
+
ethers.getAddress(CROSS_CHAIN_SEAPORT_V1_6_ADDRESS),
|
|
17
|
+
ethers.getAddress(ALTERNATE_SEAPORT_V1_6_ADDRESS),
|
|
18
|
+
])
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Gets the appropriate ItemType for a given token standard.
|
|
22
|
+
* @param tokenStandard The token standard (ERC20, ERC721, ERC1155)
|
|
23
|
+
* @returns The corresponding ItemType from Seaport
|
|
24
|
+
*/
|
|
25
|
+
export const getAssetItemType = (tokenStandard: TokenStandard) => {
|
|
26
|
+
const normalizedStandard = tokenStandard.toUpperCase()
|
|
27
|
+
switch (normalizedStandard) {
|
|
28
|
+
case "ERC20":
|
|
29
|
+
return ItemType.ERC20
|
|
30
|
+
case "ERC721":
|
|
31
|
+
return ItemType.ERC721
|
|
32
|
+
case "ERC1155":
|
|
33
|
+
return ItemType.ERC1155
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unknown schema name: ${tokenStandard}`)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Remaps shared storefront token addresses to the lazy mint adapter address.
|
|
41
|
+
*
|
|
42
|
+
* OpenSea's shared storefront contracts require special handling - when a token
|
|
43
|
+
* is from a shared storefront address, it must be remapped to the lazy mint
|
|
44
|
+
* adapter address for proper Seaport order creation.
|
|
45
|
+
*
|
|
46
|
+
* @param tokenAddress The token contract address to check
|
|
47
|
+
* @returns The lazy mint adapter address if the input is a shared storefront address,
|
|
48
|
+
* otherwise returns the original address unchanged
|
|
49
|
+
*/
|
|
50
|
+
export const remapSharedStorefrontAddress = (tokenAddress: string): string => {
|
|
51
|
+
if (SHARED_STOREFRONT_ADDRESSES.has(tokenAddress.toLowerCase())) {
|
|
52
|
+
return ethers.getAddress(
|
|
53
|
+
SHARED_STOREFRONT_LAZY_MINT_ADAPTER_CROSS_CHAIN_ADDRESS,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
return tokenAddress
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns if a protocol address is valid.
|
|
61
|
+
* @param protocolAddress The protocol address
|
|
62
|
+
*/
|
|
63
|
+
export const isValidProtocol = (protocolAddress: string): boolean => {
|
|
64
|
+
try {
|
|
65
|
+
return VALID_PROTOCOL_ADDRESSES.has(ethers.getAddress(protocolAddress))
|
|
66
|
+
} catch {
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Throws an error if the protocol address is not valid.
|
|
73
|
+
* @param protocolAddress The protocol address
|
|
74
|
+
*/
|
|
75
|
+
export const requireValidProtocol = (protocolAddress: string) => {
|
|
76
|
+
if (!isValidProtocol(protocolAddress)) {
|
|
77
|
+
throw new Error(`Unsupported protocol address: ${protocolAddress}`)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get the Seaport instance for a given protocol address.
|
|
83
|
+
* This is a shared utility to avoid duplicating the logic across multiple SDK manager classes.
|
|
84
|
+
* @param protocolAddress The protocol address
|
|
85
|
+
* @param seaport The Seaport instance
|
|
86
|
+
* @returns The Seaport instance for the given protocol address
|
|
87
|
+
* @throws Error if the protocol address is not supported
|
|
88
|
+
*/
|
|
89
|
+
export const getSeaportInstance = (
|
|
90
|
+
protocolAddress: string,
|
|
91
|
+
seaport: Seaport,
|
|
92
|
+
): Seaport => {
|
|
93
|
+
requireValidProtocol(protocolAddress)
|
|
94
|
+
return seaport
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get the Seaport version string for a given protocol address.
|
|
99
|
+
* @param protocolAddress The protocol address
|
|
100
|
+
* @returns The version string (e.g., "1.6")
|
|
101
|
+
* @throws Error if the protocol address is not supported
|
|
102
|
+
*/
|
|
103
|
+
export const getSeaportVersion = (protocolAddress: string): string => {
|
|
104
|
+
requireValidProtocol(protocolAddress)
|
|
105
|
+
return "1.6"
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Decodes an encoded string of token IDs into an array of individual token IDs using bigint for precise calculations.
|
|
110
|
+
*
|
|
111
|
+
* The encoded token IDs can be in the following formats:
|
|
112
|
+
* 1. Single numbers: '123' => ['123']
|
|
113
|
+
* 2. Comma-separated numbers: '1,2,3,4' => ['1', '2', '3', '4']
|
|
114
|
+
* 3. Ranges of numbers: '5:8' => ['5', '6', '7', '8']
|
|
115
|
+
* 4. Combinations of single numbers and ranges: '1,3:5,8' => ['1', '3', '4', '5', '8']
|
|
116
|
+
* 5. Wildcard '*' (matches all token IDs): '*' => ['*']
|
|
117
|
+
*
|
|
118
|
+
* @param encodedTokenIds - The encoded string of token IDs to be decoded.
|
|
119
|
+
* @returns An array of individual token IDs after decoding the input.
|
|
120
|
+
*
|
|
121
|
+
* @throws {Error} If the input is not correctly formatted or if bigint operations fail.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const encoded = '1,3:5,8';
|
|
125
|
+
* const decoded = decodeTokenIds(encoded); // Output: ['1', '3', '4', '5', '8']
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const encodedWildcard = '*';
|
|
129
|
+
* const decodedWildcard = decodeTokenIds(encodedWildcard); // Output: ['*']
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* const emptyEncoded = '';
|
|
133
|
+
* const decodedEmpty = decodeTokenIds(emptyEncoded); // Output: []
|
|
134
|
+
*/
|
|
135
|
+
export const decodeTokenIds = (encodedTokenIds: string): string[] => {
|
|
136
|
+
if (encodedTokenIds === "*") {
|
|
137
|
+
return ["*"]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (encodedTokenIds === "") {
|
|
141
|
+
return []
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Check for whitespace and provide helpful error message
|
|
145
|
+
if (/\s/.test(encodedTokenIds)) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
"Invalid input format: whitespace is not allowed. Expected format: '1,2,3' or '1:5' or '1,3:5,8' (no spaces).",
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const validFormatRegex = /^(\d+(:\d+)?)(,\d+(:\d+)?)*$/
|
|
152
|
+
|
|
153
|
+
if (!validFormatRegex.test(encodedTokenIds)) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
"Invalid input format. Expected a valid comma-separated list of numbers and ranges.",
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const ranges = encodedTokenIds.split(",")
|
|
160
|
+
const tokenIds: string[] = []
|
|
161
|
+
|
|
162
|
+
for (const range of ranges) {
|
|
163
|
+
if (range.includes(":")) {
|
|
164
|
+
const [startStr, endStr] = range.split(":")
|
|
165
|
+
const start = BigInt(startStr)
|
|
166
|
+
const end = BigInt(endStr)
|
|
167
|
+
const diff = end - start + 1n
|
|
168
|
+
|
|
169
|
+
if (diff <= 0) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Invalid range. End value: ${end} must be greater than or equal to the start value: ${start}.`,
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (let i = 0n; i < diff; i += 1n) {
|
|
176
|
+
tokenIds.push((start + i).toString())
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
const tokenId = BigInt(range)
|
|
180
|
+
tokenIds.push(tokenId.toString())
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return tokenIds
|
|
185
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { OpenSeaRateLimitError } from "../types"
|
|
2
|
+
import { pluralize } from "./stringHelper"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration for rate limit handling
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_MAX_RETRIES = 3
|
|
8
|
+
const DEFAULT_BASE_RETRY_DELAY_MS = 1000
|
|
9
|
+
const EXPONENTIAL_BACKOFF_BASE = 2
|
|
10
|
+
const MILLISECONDS_PER_SECOND = 1000
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* HTTP status codes that indicate rate limiting
|
|
14
|
+
*/
|
|
15
|
+
const RATE_LIMIT_STATUS_CODE = 429
|
|
16
|
+
const CUSTOM_RATE_LIMIT_STATUS_CODE = 599
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options for handling rate-limited operations with retries.
|
|
20
|
+
* This is exported for SDK consumers who may want to use executeWithRateLimit
|
|
21
|
+
* for their own OpenSea API integrations.
|
|
22
|
+
*/
|
|
23
|
+
export interface RateLimitOptions {
|
|
24
|
+
/** Logger function for logging progress */
|
|
25
|
+
logger?: (message: string) => void
|
|
26
|
+
/** Maximum number of retry attempts for rate limit errors */
|
|
27
|
+
maxRetries?: number
|
|
28
|
+
/** Base delay in ms to wait after a rate limit error if retry-after header is not present */
|
|
29
|
+
baseRetryDelay?: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Sleep for a specified duration
|
|
34
|
+
* @param ms Duration in milliseconds
|
|
35
|
+
*/
|
|
36
|
+
function sleep(ms: number): Promise<void> {
|
|
37
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Execute an async operation with automatic retry on rate limit errors.
|
|
42
|
+
* Respects the retry-after header when present, otherwise uses exponential backoff.
|
|
43
|
+
*
|
|
44
|
+
* @param operation The async operation to execute
|
|
45
|
+
* @param options Configuration for rate limit handling
|
|
46
|
+
* @returns The result of the operation
|
|
47
|
+
* @throws The last error encountered if all retries are exhausted
|
|
48
|
+
*/
|
|
49
|
+
export async function executeWithRateLimit<T>(
|
|
50
|
+
operation: () => Promise<T>,
|
|
51
|
+
options: RateLimitOptions = {},
|
|
52
|
+
): Promise<T> {
|
|
53
|
+
const {
|
|
54
|
+
logger = () => {},
|
|
55
|
+
maxRetries = DEFAULT_MAX_RETRIES,
|
|
56
|
+
baseRetryDelay = DEFAULT_BASE_RETRY_DELAY_MS,
|
|
57
|
+
} = options
|
|
58
|
+
|
|
59
|
+
let lastError: Error | undefined
|
|
60
|
+
|
|
61
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
62
|
+
try {
|
|
63
|
+
return await operation()
|
|
64
|
+
} catch (error) {
|
|
65
|
+
lastError = error as Error
|
|
66
|
+
const rateLimitError = error as OpenSeaRateLimitError
|
|
67
|
+
|
|
68
|
+
// Check if this is a rate limit error by status code (robust) or retry-after header
|
|
69
|
+
const isRateLimitError =
|
|
70
|
+
rateLimitError.statusCode === RATE_LIMIT_STATUS_CODE ||
|
|
71
|
+
rateLimitError.statusCode === CUSTOM_RATE_LIMIT_STATUS_CODE ||
|
|
72
|
+
rateLimitError.retryAfter !== undefined
|
|
73
|
+
|
|
74
|
+
if (!isRateLimitError || attempt === maxRetries) {
|
|
75
|
+
// Not a rate limit error or out of retries, throw the error
|
|
76
|
+
throw error
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Calculate delay
|
|
80
|
+
let delayMs: number
|
|
81
|
+
if (rateLimitError.retryAfter !== undefined) {
|
|
82
|
+
delayMs = rateLimitError.retryAfter * MILLISECONDS_PER_SECOND
|
|
83
|
+
logger(
|
|
84
|
+
`Rate limit hit. Waiting ${rateLimitError.retryAfter} seconds before retry (attempt ${attempt + 1}/${maxRetries})...`,
|
|
85
|
+
)
|
|
86
|
+
} else {
|
|
87
|
+
// Exponential backoff
|
|
88
|
+
delayMs = baseRetryDelay * EXPONENTIAL_BACKOFF_BASE ** attempt
|
|
89
|
+
const delaySeconds = delayMs / MILLISECONDS_PER_SECOND
|
|
90
|
+
logger(
|
|
91
|
+
`Rate limit hit. Waiting ${delaySeconds} seconds before retry (attempt ${attempt + 1}/${maxRetries})...`,
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await sleep(delayMs)
|
|
96
|
+
logger(`Retrying operation...`)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Should never reach here, but TypeScript needs this
|
|
101
|
+
throw lastError
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Execute an array of async operations sequentially with rate limit handling.
|
|
106
|
+
* Logs progress after each operation.
|
|
107
|
+
*
|
|
108
|
+
* @param operations Array of async operations to execute
|
|
109
|
+
* @param options Configuration for rate limit handling and progress logging
|
|
110
|
+
* @returns Array of results from each operation
|
|
111
|
+
*/
|
|
112
|
+
export async function executeSequentialWithRateLimit<T>(
|
|
113
|
+
operations: Array<() => Promise<T>>,
|
|
114
|
+
options: RateLimitOptions & {
|
|
115
|
+
operationName?: string
|
|
116
|
+
} = {},
|
|
117
|
+
): Promise<T[]> {
|
|
118
|
+
const {
|
|
119
|
+
logger = () => {},
|
|
120
|
+
operationName = "operation",
|
|
121
|
+
...rateLimitOptions
|
|
122
|
+
} = options
|
|
123
|
+
|
|
124
|
+
const results: T[] = []
|
|
125
|
+
const total = operations.length
|
|
126
|
+
|
|
127
|
+
logger(`Starting ${total} ${pluralize(total, operationName)}...`)
|
|
128
|
+
|
|
129
|
+
for (let i = 0; i < operations.length; i++) {
|
|
130
|
+
const operation = operations[i]
|
|
131
|
+
logger(`Executing ${operationName} ${i + 1}/${total}...`)
|
|
132
|
+
|
|
133
|
+
const result = await executeWithRateLimit(operation, {
|
|
134
|
+
...rateLimitOptions,
|
|
135
|
+
logger,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
results.push(result)
|
|
139
|
+
logger(`Completed ${operationName} ${i + 1}/${total}`)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
logger(
|
|
143
|
+
`All ${total} ${pluralize(total, operationName)} completed successfully`,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
return results
|
|
147
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for string formatting and manipulation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pluralizes a word based on count.
|
|
7
|
+
*
|
|
8
|
+
* @param count The number of items
|
|
9
|
+
* @param singular The singular form of the word
|
|
10
|
+
* @param plural Optional custom plural form. If not provided, adds 's' to singular
|
|
11
|
+
* @returns The appropriately pluralized word
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* pluralize(1, 'listing') // 'listing'
|
|
15
|
+
* pluralize(5, 'listing') // 'listings'
|
|
16
|
+
* pluralize(1, 'query', 'queries') // 'query'
|
|
17
|
+
* pluralize(3, 'query', 'queries') // 'queries'
|
|
18
|
+
*/
|
|
19
|
+
export function pluralize(
|
|
20
|
+
count: number,
|
|
21
|
+
singular: string,
|
|
22
|
+
plural?: string,
|
|
23
|
+
): string {
|
|
24
|
+
return count === 1 ? singular : plural || `${singular}s`
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ethers } from "ethers"
|
|
2
|
+
|
|
3
|
+
export * from "./chain"
|
|
4
|
+
// Re-export all utilities from specialized modules
|
|
5
|
+
export * from "./converters"
|
|
6
|
+
export * from "./fees"
|
|
7
|
+
export * from "./protocol"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Estimate gas usage for a transaction.
|
|
11
|
+
* @param provider The Provider
|
|
12
|
+
* @param from Address sending transaction
|
|
13
|
+
* @param to Destination contract address
|
|
14
|
+
* @param data Data to send to contract
|
|
15
|
+
* @param value Value in ETH to send with data
|
|
16
|
+
*/
|
|
17
|
+
export async function estimateGas(
|
|
18
|
+
provider: ethers.Provider,
|
|
19
|
+
{ from, to, data, value = 0n }: ethers.Transaction,
|
|
20
|
+
) {
|
|
21
|
+
return await provider.estimateGas({
|
|
22
|
+
from,
|
|
23
|
+
to,
|
|
24
|
+
value: value.toString(),
|
|
25
|
+
data,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ErrorWithCode extends Error {
|
|
30
|
+
code: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const hasErrorCode = (error: unknown): error is ErrorWithCode => {
|
|
34
|
+
const untypedError = error as Partial<ErrorWithCode>
|
|
35
|
+
return !!untypedError.code
|
|
36
|
+
}
|