@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,478 @@
|
|
|
1
|
+
import { SeaportABI } from "@opensea/seaport-js/lib/abi/Seaport"
|
|
2
|
+
import type { OrderComponents } from "@opensea/seaport-js/lib/types"
|
|
3
|
+
import { type BigNumberish, ethers, type Overrides, type Signer } from "ethers"
|
|
4
|
+
import type { Listing, Offer, Order } from "../api/types"
|
|
5
|
+
import {
|
|
6
|
+
computePrivateListingValue,
|
|
7
|
+
constructPrivateListingCounterOrder,
|
|
8
|
+
getPrivateListingFulfillments,
|
|
9
|
+
} from "../orders/privateListings"
|
|
10
|
+
import { OrderType, type OrderV2 } from "../orders/types"
|
|
11
|
+
import { DEFAULT_SEAPORT_CONTRACT_ADDRESS } from "../orders/utils"
|
|
12
|
+
import { type AssetWithTokenId, EventType, OrderSide } from "../types"
|
|
13
|
+
import {
|
|
14
|
+
getSeaportInstance,
|
|
15
|
+
hasErrorCode,
|
|
16
|
+
requireValidProtocol,
|
|
17
|
+
} from "../utils/utils"
|
|
18
|
+
import type { SDKContext } from "./context"
|
|
19
|
+
import type { OrdersManager } from "./orders"
|
|
20
|
+
|
|
21
|
+
const FULFILL_BASIC_ORDER_ALIAS = "fulfillBasicOrder_efficient_6GL6yc"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Manager for order fulfillment and validation operations.
|
|
25
|
+
* Handles fulfilling orders, validating orders onchain, and approving orders.
|
|
26
|
+
*/
|
|
27
|
+
export class FulfillmentManager {
|
|
28
|
+
constructor(
|
|
29
|
+
private context: SDKContext,
|
|
30
|
+
private ordersManager: OrdersManager,
|
|
31
|
+
) {}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Fulfill a private order for a designated address.
|
|
35
|
+
* @param options
|
|
36
|
+
* @param options.order The order to fulfill
|
|
37
|
+
* @param options.accountAddress Address of the wallet taking the order.
|
|
38
|
+
* @param options.domain An optional domain to be hashed and included at the end of fulfillment calldata.
|
|
39
|
+
* This can be used for onchain order attribution to assist with analytics.
|
|
40
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
41
|
+
* @returns Transaction hash of the order.
|
|
42
|
+
*/
|
|
43
|
+
private async fulfillPrivateOrder({
|
|
44
|
+
order,
|
|
45
|
+
accountAddress,
|
|
46
|
+
domain,
|
|
47
|
+
overrides,
|
|
48
|
+
}: {
|
|
49
|
+
order: OrderV2
|
|
50
|
+
accountAddress: string
|
|
51
|
+
domain?: string
|
|
52
|
+
overrides?: Overrides
|
|
53
|
+
}): Promise<string> {
|
|
54
|
+
if (!order.taker?.address) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Order is not a private listing - must have a taker address",
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
const counterOrder = constructPrivateListingCounterOrder(
|
|
60
|
+
order.protocolData,
|
|
61
|
+
order.taker.address,
|
|
62
|
+
)
|
|
63
|
+
const fulfillments = getPrivateListingFulfillments(order.protocolData)
|
|
64
|
+
|
|
65
|
+
// Compute ETH value from original order's consideration items
|
|
66
|
+
// This handles both standard private listings and zero-payment listings (e.g., rewards)
|
|
67
|
+
const value = computePrivateListingValue(
|
|
68
|
+
order.protocolData,
|
|
69
|
+
order.taker.address,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
const seaport = getSeaportInstance(
|
|
73
|
+
order.protocolAddress,
|
|
74
|
+
this.context.seaport,
|
|
75
|
+
)
|
|
76
|
+
const transaction = await seaport
|
|
77
|
+
.matchOrders({
|
|
78
|
+
orders: [order.protocolData, counterOrder],
|
|
79
|
+
fulfillments,
|
|
80
|
+
overrides: {
|
|
81
|
+
...overrides,
|
|
82
|
+
value,
|
|
83
|
+
},
|
|
84
|
+
accountAddress,
|
|
85
|
+
domain,
|
|
86
|
+
})
|
|
87
|
+
.transact()
|
|
88
|
+
const transactionReceipt = await transaction.wait()
|
|
89
|
+
if (!transactionReceipt) {
|
|
90
|
+
throw new Error("Missing transaction receipt")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
await this.context.confirmTransaction(
|
|
94
|
+
transactionReceipt.hash,
|
|
95
|
+
EventType.MatchOrders,
|
|
96
|
+
"Fulfilling order",
|
|
97
|
+
)
|
|
98
|
+
return transactionReceipt.hash
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Fulfill an order for an asset. The order can be either a listing or an offer.
|
|
103
|
+
* Uses the OpenSea API to generate fulfillment transaction data and executes it directly.
|
|
104
|
+
* @param options
|
|
105
|
+
* @param options.order The order to fulfill, a.k.a. "take"
|
|
106
|
+
* @param options.accountAddress Address of the wallet taking the offer.
|
|
107
|
+
* @param options.assetContractAddress Optional address of the NFT contract for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
|
|
108
|
+
* @param options.tokenId Optional token ID for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
|
|
109
|
+
* @param options.unitsToFill Optional number of units to fill. Defaults to 1 for both listings and offers.
|
|
110
|
+
* @param options.recipientAddress Optional recipient address for the NFT when fulfilling a listing. Not applicable for offers.
|
|
111
|
+
* @param options.includeOptionalCreatorFees Whether to include optional creator fees in the fulfillment. If creator fees are already required, this is a no-op. Defaults to false.
|
|
112
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
113
|
+
* @returns Transaction hash of the order.
|
|
114
|
+
*
|
|
115
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
116
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
117
|
+
* @throws Error if a signer is not provided (read-only providers cannot fulfill orders).
|
|
118
|
+
* @throws Error if the order hash is not available.
|
|
119
|
+
*/
|
|
120
|
+
async fulfillOrder({
|
|
121
|
+
order,
|
|
122
|
+
accountAddress,
|
|
123
|
+
assetContractAddress,
|
|
124
|
+
tokenId,
|
|
125
|
+
unitsToFill,
|
|
126
|
+
recipientAddress,
|
|
127
|
+
includeOptionalCreatorFees = false,
|
|
128
|
+
overrides,
|
|
129
|
+
}: {
|
|
130
|
+
order: OrderV2 | Order | Listing | Offer
|
|
131
|
+
accountAddress: string
|
|
132
|
+
assetContractAddress?: string
|
|
133
|
+
tokenId?: string
|
|
134
|
+
unitsToFill?: BigNumberish
|
|
135
|
+
recipientAddress?: string
|
|
136
|
+
includeOptionalCreatorFees?: boolean
|
|
137
|
+
overrides?: Overrides
|
|
138
|
+
}): Promise<string> {
|
|
139
|
+
await this.context.requireAccountIsAvailable(accountAddress)
|
|
140
|
+
|
|
141
|
+
const protocolAddress =
|
|
142
|
+
(order as OrderV2).protocolAddress ?? (order as Order).protocol_address
|
|
143
|
+
requireValidProtocol(protocolAddress)
|
|
144
|
+
|
|
145
|
+
const orderHash =
|
|
146
|
+
(order as OrderV2).orderHash ?? (order as Order).order_hash
|
|
147
|
+
|
|
148
|
+
const side =
|
|
149
|
+
(order as OrderV2).side ??
|
|
150
|
+
("type" in order &&
|
|
151
|
+
[OrderType.BASIC, OrderType.ENGLISH].includes(order.type as OrderType)
|
|
152
|
+
? OrderSide.LISTING
|
|
153
|
+
: OrderSide.OFFER)
|
|
154
|
+
|
|
155
|
+
const isPrivateListing = "taker" in order ? !!order.taker : false
|
|
156
|
+
if (isPrivateListing) {
|
|
157
|
+
return this.fulfillPrivateOrder({
|
|
158
|
+
order: order as OrderV2,
|
|
159
|
+
accountAddress,
|
|
160
|
+
overrides,
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Get fulfillment data from the API
|
|
165
|
+
if (!orderHash) {
|
|
166
|
+
throw new Error("Order hash is required to fulfill an order")
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Convert unitsToFill to string, defaulting to "1" if not provided
|
|
170
|
+
const unitsToFillStr =
|
|
171
|
+
unitsToFill !== undefined ? unitsToFill.toString() : "1"
|
|
172
|
+
|
|
173
|
+
const fulfillmentData = await this.context.api.generateFulfillmentData(
|
|
174
|
+
accountAddress,
|
|
175
|
+
orderHash,
|
|
176
|
+
protocolAddress,
|
|
177
|
+
side,
|
|
178
|
+
assetContractAddress,
|
|
179
|
+
tokenId,
|
|
180
|
+
unitsToFillStr,
|
|
181
|
+
recipientAddress,
|
|
182
|
+
includeOptionalCreatorFees,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
// Use the transaction data returned by the API
|
|
186
|
+
const transaction = fulfillmentData.fulfillment_data.transaction
|
|
187
|
+
const inputData = transaction.input_data
|
|
188
|
+
|
|
189
|
+
// Use Seaport ABI to encode the transaction
|
|
190
|
+
const seaportInterface = new ethers.Interface(SeaportABI)
|
|
191
|
+
|
|
192
|
+
// Extract function name and build parameters array in correct order
|
|
193
|
+
const rawFunctionName = transaction.function.split("(")[0]
|
|
194
|
+
const functionName =
|
|
195
|
+
rawFunctionName === FULFILL_BASIC_ORDER_ALIAS
|
|
196
|
+
? "fulfillBasicOrder"
|
|
197
|
+
: rawFunctionName
|
|
198
|
+
let params: unknown[]
|
|
199
|
+
|
|
200
|
+
// Order parameters based on the function being called
|
|
201
|
+
if (
|
|
202
|
+
functionName === "fulfillAdvancedOrder" &&
|
|
203
|
+
"advancedOrder" in inputData
|
|
204
|
+
) {
|
|
205
|
+
params = [
|
|
206
|
+
inputData.advancedOrder,
|
|
207
|
+
inputData.criteriaResolvers || [],
|
|
208
|
+
inputData.fulfillerConduitKey ||
|
|
209
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
210
|
+
inputData.recipient,
|
|
211
|
+
]
|
|
212
|
+
} else if (
|
|
213
|
+
(functionName === "fulfillBasicOrder" ||
|
|
214
|
+
rawFunctionName === FULFILL_BASIC_ORDER_ALIAS) &&
|
|
215
|
+
"basicOrderParameters" in inputData
|
|
216
|
+
) {
|
|
217
|
+
params = [inputData.basicOrderParameters]
|
|
218
|
+
} else if (functionName === "fulfillOrder" && "order" in inputData) {
|
|
219
|
+
params = [
|
|
220
|
+
inputData.order,
|
|
221
|
+
inputData.fulfillerConduitKey ||
|
|
222
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
223
|
+
]
|
|
224
|
+
} else {
|
|
225
|
+
// Fallback: try to use values in object order
|
|
226
|
+
params = Object.values(inputData)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const encodedData = seaportInterface.encodeFunctionData(
|
|
230
|
+
functionName,
|
|
231
|
+
params,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
// Send the transaction using the signer from context
|
|
235
|
+
const signer = this.context.signerOrProvider as Signer
|
|
236
|
+
const tx = await signer.sendTransaction({
|
|
237
|
+
to: transaction.to,
|
|
238
|
+
value: transaction.value,
|
|
239
|
+
data: encodedData,
|
|
240
|
+
...overrides,
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
await this.context.confirmTransaction(
|
|
244
|
+
tx.hash,
|
|
245
|
+
EventType.MatchOrders,
|
|
246
|
+
"Fulfilling order",
|
|
247
|
+
)
|
|
248
|
+
return tx.hash
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Returns whether an order is fulfillable.
|
|
253
|
+
* An order may not be fulfillable if a target item's transfer function
|
|
254
|
+
* is locked for some reason, e.g. an item is being rented within a game
|
|
255
|
+
* or trading has been locked for an item type.
|
|
256
|
+
* @param options
|
|
257
|
+
* @param options.order Order to check
|
|
258
|
+
* @param options.accountAddress The account address that will be fulfilling the order
|
|
259
|
+
* @returns True if the order is fulfillable, else False.
|
|
260
|
+
*
|
|
261
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
262
|
+
*/
|
|
263
|
+
async isOrderFulfillable({
|
|
264
|
+
order,
|
|
265
|
+
accountAddress,
|
|
266
|
+
}: {
|
|
267
|
+
order: OrderV2
|
|
268
|
+
accountAddress: string
|
|
269
|
+
}): Promise<boolean> {
|
|
270
|
+
requireValidProtocol(order.protocolAddress)
|
|
271
|
+
|
|
272
|
+
const seaport = getSeaportInstance(
|
|
273
|
+
order.protocolAddress,
|
|
274
|
+
this.context.seaport,
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
const isValid = await seaport
|
|
279
|
+
.validate([order.protocolData], accountAddress)
|
|
280
|
+
.staticCall()
|
|
281
|
+
return !!isValid
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (hasErrorCode(error) && error.code === "CALL_EXCEPTION") {
|
|
284
|
+
return false
|
|
285
|
+
}
|
|
286
|
+
throw error
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Instead of signing an off-chain order, this method allows you to approve an order
|
|
292
|
+
* with an onchain transaction.
|
|
293
|
+
* @param order Order to approve
|
|
294
|
+
* @param 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.
|
|
295
|
+
* @returns Transaction hash of the approval transaction
|
|
296
|
+
*
|
|
297
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
298
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
299
|
+
*/
|
|
300
|
+
async approveOrder(order: OrderV2, domain?: string) {
|
|
301
|
+
await this.context.requireAccountIsAvailable(order.maker.address)
|
|
302
|
+
requireValidProtocol(order.protocolAddress)
|
|
303
|
+
|
|
304
|
+
this.context.dispatch(EventType.ApproveOrder, {
|
|
305
|
+
orderV2: order,
|
|
306
|
+
accountAddress: order.maker.address,
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
const seaport = getSeaportInstance(
|
|
310
|
+
order.protocolAddress,
|
|
311
|
+
this.context.seaport,
|
|
312
|
+
)
|
|
313
|
+
const transaction = await seaport
|
|
314
|
+
.validate([order.protocolData], order.maker.address, domain)
|
|
315
|
+
.transact()
|
|
316
|
+
|
|
317
|
+
await this.context.confirmTransaction(
|
|
318
|
+
transaction.hash,
|
|
319
|
+
EventType.ApproveOrder,
|
|
320
|
+
"Approving order",
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
return transaction.hash
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Validates an order onchain using Seaport's validate() method. This submits the order onchain
|
|
328
|
+
* and pre-validates the order using Seaport, which makes it cheaper to fulfill since a signature
|
|
329
|
+
* is not needed to be verified during fulfillment for the order, but is not strictly required
|
|
330
|
+
* and the alternative is orders can be submitted to the API for free instead of sent onchain.
|
|
331
|
+
* @param orderComponents Order components to validate onchain
|
|
332
|
+
* @param accountAddress Address of the wallet that will pay the gas to validate the order
|
|
333
|
+
* @returns Transaction hash of the validation transaction
|
|
334
|
+
*
|
|
335
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
336
|
+
*/
|
|
337
|
+
async validateOrderOnchain(
|
|
338
|
+
orderComponents: OrderComponents,
|
|
339
|
+
accountAddress: string,
|
|
340
|
+
) {
|
|
341
|
+
await this.context.requireAccountIsAvailable(accountAddress)
|
|
342
|
+
|
|
343
|
+
this.context.dispatch(EventType.ApproveOrder, {
|
|
344
|
+
orderV2: { protocolData: orderComponents } as unknown as OrderV2,
|
|
345
|
+
accountAddress,
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
const seaport = getSeaportInstance(
|
|
349
|
+
DEFAULT_SEAPORT_CONTRACT_ADDRESS,
|
|
350
|
+
this.context.seaport,
|
|
351
|
+
)
|
|
352
|
+
const transaction = await seaport
|
|
353
|
+
.validate(
|
|
354
|
+
[{ parameters: orderComponents, signature: "0x" }],
|
|
355
|
+
accountAddress,
|
|
356
|
+
)
|
|
357
|
+
.transact()
|
|
358
|
+
|
|
359
|
+
await this.context.confirmTransaction(
|
|
360
|
+
transaction.hash,
|
|
361
|
+
EventType.ApproveOrder,
|
|
362
|
+
"Validating order onchain",
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
return transaction.hash
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Create and validate a listing onchain. Combines order building with onchain validation.
|
|
370
|
+
* Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
|
|
371
|
+
* @param options
|
|
372
|
+
* @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
|
|
373
|
+
* @param options.accountAddress Address of the wallet making the listing
|
|
374
|
+
* @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
|
|
375
|
+
* @param options.quantity Number of assets to list. Defaults to 1.
|
|
376
|
+
* @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
|
|
377
|
+
* @param options.salt Arbitrary salt. Auto-generated if not provided.
|
|
378
|
+
* @param options.listingTime When order becomes fulfillable (UTC seconds). Defaults to now.
|
|
379
|
+
* @param options.expirationTime Expiration time (UTC seconds).
|
|
380
|
+
* @param options.buyerAddress Optional buyer restriction. Only this address can purchase.
|
|
381
|
+
* @param options.includeOptionalCreatorFees Include optional creator fees. Default: false.
|
|
382
|
+
* @param options.zone Zone for order protection. Defaults to no zone.
|
|
383
|
+
* @returns Transaction hash
|
|
384
|
+
*
|
|
385
|
+
* @throws Error if asset missing token id or accountAddress unavailable.
|
|
386
|
+
*/
|
|
387
|
+
async createListingAndValidateOnchain({
|
|
388
|
+
asset,
|
|
389
|
+
accountAddress,
|
|
390
|
+
amount,
|
|
391
|
+
quantity = 1,
|
|
392
|
+
domain,
|
|
393
|
+
salt,
|
|
394
|
+
listingTime,
|
|
395
|
+
expirationTime,
|
|
396
|
+
buyerAddress,
|
|
397
|
+
includeOptionalCreatorFees = false,
|
|
398
|
+
zone,
|
|
399
|
+
}: {
|
|
400
|
+
asset: AssetWithTokenId
|
|
401
|
+
accountAddress: string
|
|
402
|
+
amount: BigNumberish
|
|
403
|
+
quantity?: BigNumberish
|
|
404
|
+
domain?: string
|
|
405
|
+
salt?: BigNumberish
|
|
406
|
+
listingTime?: number
|
|
407
|
+
expirationTime?: number
|
|
408
|
+
buyerAddress?: string
|
|
409
|
+
includeOptionalCreatorFees?: boolean
|
|
410
|
+
zone?: string
|
|
411
|
+
}): Promise<string> {
|
|
412
|
+
const orderComponents =
|
|
413
|
+
await this.ordersManager.buildListingOrderComponents({
|
|
414
|
+
asset,
|
|
415
|
+
accountAddress,
|
|
416
|
+
amount,
|
|
417
|
+
quantity,
|
|
418
|
+
domain,
|
|
419
|
+
salt,
|
|
420
|
+
listingTime,
|
|
421
|
+
expirationTime,
|
|
422
|
+
buyerAddress,
|
|
423
|
+
includeOptionalCreatorFees,
|
|
424
|
+
zone,
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
return this.validateOrderOnchain(orderComponents, accountAddress)
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Create and validate an offer onchain. Combines order building with onchain validation.
|
|
432
|
+
* Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
|
|
433
|
+
* @param options
|
|
434
|
+
* @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
|
|
435
|
+
* @param options.accountAddress Address of the wallet making the offer.
|
|
436
|
+
* @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
|
|
437
|
+
* @param options.quantity Number of assets to bid for. Defaults to 1.
|
|
438
|
+
* @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
|
|
439
|
+
* @param options.salt Arbitrary salt. Auto-generated if not provided.
|
|
440
|
+
* @param options.expirationTime Expiration time (UTC seconds).
|
|
441
|
+
* @param options.zone Zone for order protection. Defaults to chain's signed zone.
|
|
442
|
+
* @returns Transaction hash
|
|
443
|
+
*
|
|
444
|
+
* @throws Error if asset missing token id or accountAddress unavailable.
|
|
445
|
+
*/
|
|
446
|
+
async createOfferAndValidateOnchain({
|
|
447
|
+
asset,
|
|
448
|
+
accountAddress,
|
|
449
|
+
amount,
|
|
450
|
+
quantity = 1,
|
|
451
|
+
domain,
|
|
452
|
+
salt,
|
|
453
|
+
expirationTime,
|
|
454
|
+
zone,
|
|
455
|
+
}: {
|
|
456
|
+
asset: AssetWithTokenId
|
|
457
|
+
accountAddress: string
|
|
458
|
+
amount: BigNumberish
|
|
459
|
+
quantity?: BigNumberish
|
|
460
|
+
domain?: string
|
|
461
|
+
salt?: BigNumberish
|
|
462
|
+
expirationTime?: BigNumberish
|
|
463
|
+
zone?: string
|
|
464
|
+
}): Promise<string> {
|
|
465
|
+
const orderComponents = await this.ordersManager.buildOfferOrderComponents({
|
|
466
|
+
asset,
|
|
467
|
+
accountAddress,
|
|
468
|
+
amount,
|
|
469
|
+
quantity,
|
|
470
|
+
domain,
|
|
471
|
+
salt,
|
|
472
|
+
expirationTime,
|
|
473
|
+
zone,
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
return this.validateOrderOnchain(orderComponents, accountAddress)
|
|
477
|
+
}
|
|
478
|
+
}
|