@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,346 @@
|
|
|
1
|
+
import type { OrderComponents } from "@opensea/seaport-js/lib/types"
|
|
2
|
+
import type { Overrides, Signer } from "ethers"
|
|
3
|
+
import type { Listing, Offer } from "../api/types"
|
|
4
|
+
import type { OrderV2 } from "../orders/types"
|
|
5
|
+
import { DEFAULT_SEAPORT_CONTRACT_ADDRESS } from "../orders/utils"
|
|
6
|
+
import { type Chain, EventType } from "../types"
|
|
7
|
+
import {
|
|
8
|
+
getChainId,
|
|
9
|
+
getSeaportInstance,
|
|
10
|
+
getSeaportVersion,
|
|
11
|
+
requireValidProtocol,
|
|
12
|
+
} from "../utils/utils"
|
|
13
|
+
import type { SDKContext } from "./context"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Order cancellation operations
|
|
17
|
+
*/
|
|
18
|
+
export class CancellationManager {
|
|
19
|
+
constructor(private context: SDKContext) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Cancel an order onchain, preventing it from ever being fulfilled.
|
|
23
|
+
* This method accepts either a full OrderV2 object or an order hash with protocol address.
|
|
24
|
+
*
|
|
25
|
+
* @param options
|
|
26
|
+
* @param options.order The order to cancel (OrderV2 object)
|
|
27
|
+
* @param options.orderHash Optional order hash to cancel. Must provide protocolAddress if using this.
|
|
28
|
+
* @param options.accountAddress The account address that will be cancelling the order.
|
|
29
|
+
* @param options.protocolAddress Required when using orderHash. The Seaport protocol address for the order.
|
|
30
|
+
* @param options.domain An optional domain to be hashed and included at the end of fulfillment calldata. This can be used for onchain order attribution to assist with analytics.
|
|
31
|
+
*
|
|
32
|
+
* @throws Error if neither order nor orderHash is provided.
|
|
33
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
34
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
35
|
+
*/
|
|
36
|
+
async cancelOrder({
|
|
37
|
+
order,
|
|
38
|
+
orderHash,
|
|
39
|
+
accountAddress,
|
|
40
|
+
protocolAddress = DEFAULT_SEAPORT_CONTRACT_ADDRESS,
|
|
41
|
+
domain,
|
|
42
|
+
}: {
|
|
43
|
+
order?: OrderV2
|
|
44
|
+
orderHash?: string
|
|
45
|
+
accountAddress: string
|
|
46
|
+
protocolAddress?: string
|
|
47
|
+
domain?: string
|
|
48
|
+
}) {
|
|
49
|
+
// Validate input
|
|
50
|
+
if (!order && !orderHash) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Either order or orderHash must be provided to cancel order",
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Check account availability after parameter validation
|
|
57
|
+
await this.context.requireAccountIsAvailable(accountAddress)
|
|
58
|
+
|
|
59
|
+
let orderComponents: OrderComponents
|
|
60
|
+
let effectiveProtocolAddress: string
|
|
61
|
+
|
|
62
|
+
if (order) {
|
|
63
|
+
// Using OrderV2 object directly
|
|
64
|
+
requireValidProtocol(order.protocolAddress)
|
|
65
|
+
effectiveProtocolAddress = order.protocolAddress
|
|
66
|
+
orderComponents = order.protocolData.parameters
|
|
67
|
+
this.context.dispatch(EventType.CancelOrder, {
|
|
68
|
+
orderV2: order,
|
|
69
|
+
accountAddress,
|
|
70
|
+
})
|
|
71
|
+
} else if (orderHash) {
|
|
72
|
+
// Fetch order from API using order hash
|
|
73
|
+
requireValidProtocol(protocolAddress)
|
|
74
|
+
const fetchedOrder = await this.context.api.getOrderByHash(
|
|
75
|
+
orderHash,
|
|
76
|
+
protocolAddress,
|
|
77
|
+
this.context.chain,
|
|
78
|
+
)
|
|
79
|
+
requireValidProtocol(fetchedOrder.protocol_address)
|
|
80
|
+
effectiveProtocolAddress = fetchedOrder.protocol_address
|
|
81
|
+
orderComponents = fetchedOrder.protocol_data.parameters
|
|
82
|
+
this.context.dispatch(EventType.CancelOrder, {
|
|
83
|
+
order: fetchedOrder,
|
|
84
|
+
accountAddress,
|
|
85
|
+
})
|
|
86
|
+
} else {
|
|
87
|
+
// Should never reach here due to earlier validation
|
|
88
|
+
throw new Error("Invalid input")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Transact and get the transaction hash
|
|
92
|
+
const transactionHash = await this.cancelSeaportOrders({
|
|
93
|
+
orders: [orderComponents],
|
|
94
|
+
accountAddress,
|
|
95
|
+
domain,
|
|
96
|
+
protocolAddress: effectiveProtocolAddress,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// Await transaction confirmation
|
|
100
|
+
await this.context.confirmTransaction(
|
|
101
|
+
transactionHash,
|
|
102
|
+
EventType.CancelOrder,
|
|
103
|
+
"Cancelling order",
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Cancel multiple orders onchain, preventing them from being fulfilled.
|
|
109
|
+
* This method accepts either full OrderV2 objects, OrderComponents, or order hashes with protocol address.
|
|
110
|
+
*
|
|
111
|
+
* **Event Behavior**: For backwards compatibility with the singular `cancelOrder` method,
|
|
112
|
+
* this method dispatches a `CancelOrder` event for the first order only, and only when
|
|
113
|
+
* an OrderV2 object is available (either provided directly or fetched via orderHashes).
|
|
114
|
+
* No event is dispatched when using OrderComponents directly, as they lack the full order data.
|
|
115
|
+
*
|
|
116
|
+
* @param options
|
|
117
|
+
* @param options.orders Array of orders to cancel. Can be OrderV2 objects or OrderComponents.
|
|
118
|
+
* @param options.orderHashes Optional array of order hashes to cancel. Must provide protocolAddress if using this.
|
|
119
|
+
* @param options.accountAddress The account address cancelling the orders.
|
|
120
|
+
* @param options.protocolAddress Required when using orderHashes. The Seaport protocol address for the orders.
|
|
121
|
+
* @param options.domain An optional domain to be hashed and included at the end of fulfillment calldata.
|
|
122
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
123
|
+
* @returns Transaction hash of the cancellation.
|
|
124
|
+
*
|
|
125
|
+
* @throws Error if orderHashes is provided without protocolAddress.
|
|
126
|
+
* @throws Error if neither orders nor orderHashes is provided.
|
|
127
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
128
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
129
|
+
*/
|
|
130
|
+
async cancelOrders({
|
|
131
|
+
orders,
|
|
132
|
+
orderHashes,
|
|
133
|
+
accountAddress,
|
|
134
|
+
protocolAddress = DEFAULT_SEAPORT_CONTRACT_ADDRESS,
|
|
135
|
+
domain,
|
|
136
|
+
overrides,
|
|
137
|
+
}: {
|
|
138
|
+
orders?: Array<OrderV2 | OrderComponents>
|
|
139
|
+
orderHashes?: string[]
|
|
140
|
+
accountAddress: string
|
|
141
|
+
protocolAddress?: string
|
|
142
|
+
domain?: string
|
|
143
|
+
overrides?: Overrides
|
|
144
|
+
}): Promise<string> {
|
|
145
|
+
// Validate input before making any external calls
|
|
146
|
+
if (!orders && !orderHashes) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
"Either orders or orderHashes must be provided to cancel orders",
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (orders && orderHashes) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
"Cannot provide both orders and orderHashes. Please use one or the other.",
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (orders && orders.length === 0) {
|
|
159
|
+
throw new Error("At least one order must be provided")
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (orderHashes && orderHashes.length === 0) {
|
|
163
|
+
throw new Error("At least one order hash must be provided")
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
requireValidProtocol(protocolAddress)
|
|
167
|
+
|
|
168
|
+
// Check account availability after parameter validation
|
|
169
|
+
await this.context.requireAccountIsAvailable(accountAddress)
|
|
170
|
+
|
|
171
|
+
let orderComponents: OrderComponents[]
|
|
172
|
+
let effectiveProtocolAddress = protocolAddress
|
|
173
|
+
|
|
174
|
+
if (orders) {
|
|
175
|
+
// Extract OrderComponents from either OrderV2 objects or use OrderComponents directly
|
|
176
|
+
let firstOrderV2: OrderV2 | undefined
|
|
177
|
+
orderComponents = orders.map(order => {
|
|
178
|
+
if ("protocolData" in order) {
|
|
179
|
+
// It's an OrderV2 object
|
|
180
|
+
const orderV2 = order as OrderV2
|
|
181
|
+
requireValidProtocol(orderV2.protocolAddress)
|
|
182
|
+
effectiveProtocolAddress = orderV2.protocolAddress
|
|
183
|
+
if (!firstOrderV2) {
|
|
184
|
+
firstOrderV2 = orderV2
|
|
185
|
+
}
|
|
186
|
+
return orderV2.protocolData.parameters
|
|
187
|
+
} else {
|
|
188
|
+
// It's already OrderComponents
|
|
189
|
+
return order as OrderComponents
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
// Dispatch event for the first OrderV2 if available
|
|
193
|
+
if (firstOrderV2) {
|
|
194
|
+
this.context.dispatch(EventType.CancelOrder, {
|
|
195
|
+
orderV2: firstOrderV2,
|
|
196
|
+
accountAddress,
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
} else if (orderHashes) {
|
|
200
|
+
// Fetch orders from the API using order hashes
|
|
201
|
+
const fetchedOrders: (Offer | Listing)[] = []
|
|
202
|
+
for (const hash of orderHashes) {
|
|
203
|
+
const fetched = await this.context.api.getOrderByHash(
|
|
204
|
+
hash,
|
|
205
|
+
protocolAddress,
|
|
206
|
+
this.context.chain,
|
|
207
|
+
)
|
|
208
|
+
fetchedOrders.push(fetched)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Extract OrderComponents from the fetched orders
|
|
212
|
+
orderComponents = fetchedOrders.map(fetched => {
|
|
213
|
+
requireValidProtocol(fetched.protocol_address)
|
|
214
|
+
effectiveProtocolAddress = fetched.protocol_address
|
|
215
|
+
return fetched.protocol_data.parameters
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
// Dispatch event for the first fetched order
|
|
219
|
+
if (fetchedOrders.length > 0) {
|
|
220
|
+
this.context.dispatch(EventType.CancelOrder, {
|
|
221
|
+
order: fetchedOrders[0],
|
|
222
|
+
accountAddress,
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
// Should never reach here due to earlier validation
|
|
227
|
+
throw new Error("Invalid input")
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Transact and get the transaction hash
|
|
231
|
+
const transactionHash = await this.cancelSeaportOrders({
|
|
232
|
+
orders: orderComponents,
|
|
233
|
+
accountAddress,
|
|
234
|
+
domain,
|
|
235
|
+
protocolAddress: effectiveProtocolAddress,
|
|
236
|
+
overrides,
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
// Await transaction confirmation
|
|
240
|
+
await this.context.confirmTransaction(
|
|
241
|
+
transactionHash,
|
|
242
|
+
EventType.CancelOrder,
|
|
243
|
+
`Cancelling ${orderComponents.length} order(s)`,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
return transactionHash
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Cancel orders onchain, preventing them from being fulfilled.
|
|
251
|
+
* @param options
|
|
252
|
+
* @param options.orders The orders to cancel
|
|
253
|
+
* @param options.accountAddress The account address cancelling the orders.
|
|
254
|
+
* @param options.domain An optional domain to be hashed and included at the end of fulfillment calldata.
|
|
255
|
+
* This can be used for onchain order attribution to assist with analytics.
|
|
256
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
257
|
+
* @returns Transaction hash of the order.
|
|
258
|
+
*/
|
|
259
|
+
private async cancelSeaportOrders({
|
|
260
|
+
orders,
|
|
261
|
+
accountAddress,
|
|
262
|
+
domain,
|
|
263
|
+
protocolAddress = DEFAULT_SEAPORT_CONTRACT_ADDRESS,
|
|
264
|
+
overrides,
|
|
265
|
+
}: {
|
|
266
|
+
orders: OrderComponents[]
|
|
267
|
+
accountAddress: string
|
|
268
|
+
domain?: string
|
|
269
|
+
protocolAddress?: string
|
|
270
|
+
overrides?: Overrides
|
|
271
|
+
}): Promise<string> {
|
|
272
|
+
const seaport = getSeaportInstance(protocolAddress, this.context.seaport)
|
|
273
|
+
|
|
274
|
+
const transaction = await seaport
|
|
275
|
+
.cancelOrders(orders, accountAddress, domain, overrides)
|
|
276
|
+
.transact()
|
|
277
|
+
|
|
278
|
+
return transaction.hash
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get the offerer signature for canceling an order offchain.
|
|
283
|
+
* The signature will only be valid if the signer address is the address of the order's offerer.
|
|
284
|
+
*/
|
|
285
|
+
async getOffererSignature(
|
|
286
|
+
protocolAddress: string,
|
|
287
|
+
orderHash: string,
|
|
288
|
+
chain: Chain,
|
|
289
|
+
) {
|
|
290
|
+
const chainId = getChainId(chain)
|
|
291
|
+
const name = "Seaport"
|
|
292
|
+
const version = getSeaportVersion(protocolAddress)
|
|
293
|
+
|
|
294
|
+
if (
|
|
295
|
+
typeof (this.context.signerOrProvider as Signer).signTypedData ===
|
|
296
|
+
"undefined"
|
|
297
|
+
) {
|
|
298
|
+
throw new Error(
|
|
299
|
+
"Please pass an ethers Signer into this sdk to derive an offerer signature",
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return (this.context.signerOrProvider as Signer).signTypedData(
|
|
304
|
+
{ chainId, name, version, verifyingContract: protocolAddress },
|
|
305
|
+
{ OrderHash: [{ name: "orderHash", type: "bytes32" }] },
|
|
306
|
+
{ orderHash },
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
|
|
312
|
+
* Protocol and Chain are required to prevent hash collisions.
|
|
313
|
+
* Please note cancellation is only assured if a fulfillment signature was not vended prior to cancellation.
|
|
314
|
+
* @param protocolAddress The Seaport address for the order.
|
|
315
|
+
* @param orderHash The order hash, or external identifier, of the order.
|
|
316
|
+
* @param chain The chain where the order is located.
|
|
317
|
+
* @param offererSignature An EIP-712 signature from the offerer of the order.
|
|
318
|
+
* If this is not provided, the API key used to initialize the SDK must belong to the order's offerer.
|
|
319
|
+
* The signature must be a EIP-712 signature consisting of the order's Seaport contract's
|
|
320
|
+
* name, version, address, and chain. The struct to sign is `OrderHash` containing a
|
|
321
|
+
* single bytes32 field.
|
|
322
|
+
* @param useSignerToDeriveOffererSignature Derive the offererSignature from the Ethers signer passed into this sdk.
|
|
323
|
+
* @returns The response from the API.
|
|
324
|
+
*/
|
|
325
|
+
async offchainCancelOrder(
|
|
326
|
+
protocolAddress: string,
|
|
327
|
+
orderHash: string,
|
|
328
|
+
chain: Chain = this.context.chain,
|
|
329
|
+
offererSignature?: string,
|
|
330
|
+
useSignerToDeriveOffererSignature?: boolean,
|
|
331
|
+
) {
|
|
332
|
+
if (useSignerToDeriveOffererSignature) {
|
|
333
|
+
offererSignature = await this.getOffererSignature(
|
|
334
|
+
protocolAddress,
|
|
335
|
+
orderHash,
|
|
336
|
+
chain,
|
|
337
|
+
)
|
|
338
|
+
}
|
|
339
|
+
return this.context.api.offchainCancelOrder(
|
|
340
|
+
protocolAddress,
|
|
341
|
+
orderHash,
|
|
342
|
+
chain,
|
|
343
|
+
offererSignature,
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Seaport } from "@opensea/seaport-js"
|
|
2
|
+
import type { JsonRpcProvider, Signer } from "ethers"
|
|
3
|
+
import type { OpenSeaAPI } from "../api/api"
|
|
4
|
+
import type { Chain, EventData, EventType } from "../types"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Shared context passed to all SDK managers.
|
|
8
|
+
* Contains common dependencies and utilities needed across managers.
|
|
9
|
+
*/
|
|
10
|
+
export interface SDKContext {
|
|
11
|
+
/** The blockchain chain being used */
|
|
12
|
+
chain: Chain
|
|
13
|
+
/** Signer or provider for blockchain interactions */
|
|
14
|
+
signerOrProvider: Signer | JsonRpcProvider
|
|
15
|
+
/** JSON-RPC provider for read operations */
|
|
16
|
+
provider: JsonRpcProvider
|
|
17
|
+
/** OpenSea API client */
|
|
18
|
+
api: OpenSeaAPI
|
|
19
|
+
/** Seaport client instance */
|
|
20
|
+
seaport: Seaport
|
|
21
|
+
/** Logger function for debugging */
|
|
22
|
+
logger: (msg: string) => void
|
|
23
|
+
/** Event dispatcher */
|
|
24
|
+
dispatch: (event: EventType, data: EventData) => void
|
|
25
|
+
/** Transaction confirmation helper */
|
|
26
|
+
confirmTransaction: (
|
|
27
|
+
hash: string,
|
|
28
|
+
event: EventType,
|
|
29
|
+
description: string,
|
|
30
|
+
) => Promise<void>
|
|
31
|
+
/** Account availability checker */
|
|
32
|
+
requireAccountIsAvailable: (address: string) => Promise<void>
|
|
33
|
+
}
|