@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,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CancellationManager = void 0;
|
|
4
|
+
const utils_1 = require("../orders/utils");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const utils_2 = require("../utils/utils");
|
|
7
|
+
/**
|
|
8
|
+
* Order cancellation operations
|
|
9
|
+
*/
|
|
10
|
+
class CancellationManager {
|
|
11
|
+
context;
|
|
12
|
+
constructor(context) {
|
|
13
|
+
this.context = context;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cancel an order onchain, preventing it from ever being fulfilled.
|
|
17
|
+
* This method accepts either a full OrderV2 object or an order hash with protocol address.
|
|
18
|
+
*
|
|
19
|
+
* @param options
|
|
20
|
+
* @param options.order The order to cancel (OrderV2 object)
|
|
21
|
+
* @param options.orderHash Optional order hash to cancel. Must provide protocolAddress if using this.
|
|
22
|
+
* @param options.accountAddress The account address that will be cancelling the order.
|
|
23
|
+
* @param options.protocolAddress Required when using orderHash. The Seaport protocol address for the order.
|
|
24
|
+
* @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.
|
|
25
|
+
*
|
|
26
|
+
* @throws Error if neither order nor orderHash is provided.
|
|
27
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
28
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
29
|
+
*/
|
|
30
|
+
async cancelOrder({ order, orderHash, accountAddress, protocolAddress = utils_1.DEFAULT_SEAPORT_CONTRACT_ADDRESS, domain, }) {
|
|
31
|
+
// Validate input
|
|
32
|
+
if (!order && !orderHash) {
|
|
33
|
+
throw new Error("Either order or orderHash must be provided to cancel order");
|
|
34
|
+
}
|
|
35
|
+
// Check account availability after parameter validation
|
|
36
|
+
await this.context.requireAccountIsAvailable(accountAddress);
|
|
37
|
+
let orderComponents;
|
|
38
|
+
let effectiveProtocolAddress;
|
|
39
|
+
if (order) {
|
|
40
|
+
// Using OrderV2 object directly
|
|
41
|
+
(0, utils_2.requireValidProtocol)(order.protocolAddress);
|
|
42
|
+
effectiveProtocolAddress = order.protocolAddress;
|
|
43
|
+
orderComponents = order.protocolData.parameters;
|
|
44
|
+
this.context.dispatch(types_1.EventType.CancelOrder, {
|
|
45
|
+
orderV2: order,
|
|
46
|
+
accountAddress,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if (orderHash) {
|
|
50
|
+
// Fetch order from API using order hash
|
|
51
|
+
(0, utils_2.requireValidProtocol)(protocolAddress);
|
|
52
|
+
const fetchedOrder = await this.context.api.getOrderByHash(orderHash, protocolAddress, this.context.chain);
|
|
53
|
+
(0, utils_2.requireValidProtocol)(fetchedOrder.protocol_address);
|
|
54
|
+
effectiveProtocolAddress = fetchedOrder.protocol_address;
|
|
55
|
+
orderComponents = fetchedOrder.protocol_data.parameters;
|
|
56
|
+
this.context.dispatch(types_1.EventType.CancelOrder, {
|
|
57
|
+
order: fetchedOrder,
|
|
58
|
+
accountAddress,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Should never reach here due to earlier validation
|
|
63
|
+
throw new Error("Invalid input");
|
|
64
|
+
}
|
|
65
|
+
// Transact and get the transaction hash
|
|
66
|
+
const transactionHash = await this.cancelSeaportOrders({
|
|
67
|
+
orders: [orderComponents],
|
|
68
|
+
accountAddress,
|
|
69
|
+
domain,
|
|
70
|
+
protocolAddress: effectiveProtocolAddress,
|
|
71
|
+
});
|
|
72
|
+
// Await transaction confirmation
|
|
73
|
+
await this.context.confirmTransaction(transactionHash, types_1.EventType.CancelOrder, "Cancelling order");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Cancel multiple orders onchain, preventing them from being fulfilled.
|
|
77
|
+
* This method accepts either full OrderV2 objects, OrderComponents, or order hashes with protocol address.
|
|
78
|
+
*
|
|
79
|
+
* **Event Behavior**: For backwards compatibility with the singular `cancelOrder` method,
|
|
80
|
+
* this method dispatches a `CancelOrder` event for the first order only, and only when
|
|
81
|
+
* an OrderV2 object is available (either provided directly or fetched via orderHashes).
|
|
82
|
+
* No event is dispatched when using OrderComponents directly, as they lack the full order data.
|
|
83
|
+
*
|
|
84
|
+
* @param options
|
|
85
|
+
* @param options.orders Array of orders to cancel. Can be OrderV2 objects or OrderComponents.
|
|
86
|
+
* @param options.orderHashes Optional array of order hashes to cancel. Must provide protocolAddress if using this.
|
|
87
|
+
* @param options.accountAddress The account address cancelling the orders.
|
|
88
|
+
* @param options.protocolAddress Required when using orderHashes. The Seaport protocol address for the orders.
|
|
89
|
+
* @param options.domain An optional domain to be hashed and included at the end of fulfillment calldata.
|
|
90
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
91
|
+
* @returns Transaction hash of the cancellation.
|
|
92
|
+
*
|
|
93
|
+
* @throws Error if orderHashes is provided without protocolAddress.
|
|
94
|
+
* @throws Error if neither orders nor orderHashes is provided.
|
|
95
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
96
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
97
|
+
*/
|
|
98
|
+
async cancelOrders({ orders, orderHashes, accountAddress, protocolAddress = utils_1.DEFAULT_SEAPORT_CONTRACT_ADDRESS, domain, overrides, }) {
|
|
99
|
+
// Validate input before making any external calls
|
|
100
|
+
if (!orders && !orderHashes) {
|
|
101
|
+
throw new Error("Either orders or orderHashes must be provided to cancel orders");
|
|
102
|
+
}
|
|
103
|
+
if (orders && orderHashes) {
|
|
104
|
+
throw new Error("Cannot provide both orders and orderHashes. Please use one or the other.");
|
|
105
|
+
}
|
|
106
|
+
if (orders && orders.length === 0) {
|
|
107
|
+
throw new Error("At least one order must be provided");
|
|
108
|
+
}
|
|
109
|
+
if (orderHashes && orderHashes.length === 0) {
|
|
110
|
+
throw new Error("At least one order hash must be provided");
|
|
111
|
+
}
|
|
112
|
+
(0, utils_2.requireValidProtocol)(protocolAddress);
|
|
113
|
+
// Check account availability after parameter validation
|
|
114
|
+
await this.context.requireAccountIsAvailable(accountAddress);
|
|
115
|
+
let orderComponents;
|
|
116
|
+
let effectiveProtocolAddress = protocolAddress;
|
|
117
|
+
if (orders) {
|
|
118
|
+
// Extract OrderComponents from either OrderV2 objects or use OrderComponents directly
|
|
119
|
+
let firstOrderV2;
|
|
120
|
+
orderComponents = orders.map(order => {
|
|
121
|
+
if ("protocolData" in order) {
|
|
122
|
+
// It's an OrderV2 object
|
|
123
|
+
const orderV2 = order;
|
|
124
|
+
(0, utils_2.requireValidProtocol)(orderV2.protocolAddress);
|
|
125
|
+
effectiveProtocolAddress = orderV2.protocolAddress;
|
|
126
|
+
if (!firstOrderV2) {
|
|
127
|
+
firstOrderV2 = orderV2;
|
|
128
|
+
}
|
|
129
|
+
return orderV2.protocolData.parameters;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// It's already OrderComponents
|
|
133
|
+
return order;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
// Dispatch event for the first OrderV2 if available
|
|
137
|
+
if (firstOrderV2) {
|
|
138
|
+
this.context.dispatch(types_1.EventType.CancelOrder, {
|
|
139
|
+
orderV2: firstOrderV2,
|
|
140
|
+
accountAddress,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else if (orderHashes) {
|
|
145
|
+
// Fetch orders from the API using order hashes
|
|
146
|
+
const fetchedOrders = [];
|
|
147
|
+
for (const hash of orderHashes) {
|
|
148
|
+
const fetched = await this.context.api.getOrderByHash(hash, protocolAddress, this.context.chain);
|
|
149
|
+
fetchedOrders.push(fetched);
|
|
150
|
+
}
|
|
151
|
+
// Extract OrderComponents from the fetched orders
|
|
152
|
+
orderComponents = fetchedOrders.map(fetched => {
|
|
153
|
+
(0, utils_2.requireValidProtocol)(fetched.protocol_address);
|
|
154
|
+
effectiveProtocolAddress = fetched.protocol_address;
|
|
155
|
+
return fetched.protocol_data.parameters;
|
|
156
|
+
});
|
|
157
|
+
// Dispatch event for the first fetched order
|
|
158
|
+
if (fetchedOrders.length > 0) {
|
|
159
|
+
this.context.dispatch(types_1.EventType.CancelOrder, {
|
|
160
|
+
order: fetchedOrders[0],
|
|
161
|
+
accountAddress,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// Should never reach here due to earlier validation
|
|
167
|
+
throw new Error("Invalid input");
|
|
168
|
+
}
|
|
169
|
+
// Transact and get the transaction hash
|
|
170
|
+
const transactionHash = await this.cancelSeaportOrders({
|
|
171
|
+
orders: orderComponents,
|
|
172
|
+
accountAddress,
|
|
173
|
+
domain,
|
|
174
|
+
protocolAddress: effectiveProtocolAddress,
|
|
175
|
+
overrides,
|
|
176
|
+
});
|
|
177
|
+
// Await transaction confirmation
|
|
178
|
+
await this.context.confirmTransaction(transactionHash, types_1.EventType.CancelOrder, `Cancelling ${orderComponents.length} order(s)`);
|
|
179
|
+
return transactionHash;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Cancel orders onchain, preventing them from being fulfilled.
|
|
183
|
+
* @param options
|
|
184
|
+
* @param options.orders The orders to cancel
|
|
185
|
+
* @param options.accountAddress The account address cancelling the orders.
|
|
186
|
+
* @param options.domain An optional domain to be hashed and included at the end of fulfillment calldata.
|
|
187
|
+
* This can be used for onchain order attribution to assist with analytics.
|
|
188
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
189
|
+
* @returns Transaction hash of the order.
|
|
190
|
+
*/
|
|
191
|
+
async cancelSeaportOrders({ orders, accountAddress, domain, protocolAddress = utils_1.DEFAULT_SEAPORT_CONTRACT_ADDRESS, overrides, }) {
|
|
192
|
+
const seaport = (0, utils_2.getSeaportInstance)(protocolAddress, this.context.seaport);
|
|
193
|
+
const transaction = await seaport
|
|
194
|
+
.cancelOrders(orders, accountAddress, domain, overrides)
|
|
195
|
+
.transact();
|
|
196
|
+
return transaction.hash;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get the offerer signature for canceling an order offchain.
|
|
200
|
+
* The signature will only be valid if the signer address is the address of the order's offerer.
|
|
201
|
+
*/
|
|
202
|
+
async getOffererSignature(protocolAddress, orderHash, chain) {
|
|
203
|
+
const chainId = (0, utils_2.getChainId)(chain);
|
|
204
|
+
const name = "Seaport";
|
|
205
|
+
const version = (0, utils_2.getSeaportVersion)(protocolAddress);
|
|
206
|
+
if (typeof this.context.signerOrProvider.signTypedData ===
|
|
207
|
+
"undefined") {
|
|
208
|
+
throw new Error("Please pass an ethers Signer into this sdk to derive an offerer signature");
|
|
209
|
+
}
|
|
210
|
+
return this.context.signerOrProvider.signTypedData({ chainId, name, version, verifyingContract: protocolAddress }, { OrderHash: [{ name: "orderHash", type: "bytes32" }] }, { orderHash });
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
|
|
214
|
+
* Protocol and Chain are required to prevent hash collisions.
|
|
215
|
+
* Please note cancellation is only assured if a fulfillment signature was not vended prior to cancellation.
|
|
216
|
+
* @param protocolAddress The Seaport address for the order.
|
|
217
|
+
* @param orderHash The order hash, or external identifier, of the order.
|
|
218
|
+
* @param chain The chain where the order is located.
|
|
219
|
+
* @param offererSignature An EIP-712 signature from the offerer of the order.
|
|
220
|
+
* If this is not provided, the API key used to initialize the SDK must belong to the order's offerer.
|
|
221
|
+
* The signature must be a EIP-712 signature consisting of the order's Seaport contract's
|
|
222
|
+
* name, version, address, and chain. The struct to sign is `OrderHash` containing a
|
|
223
|
+
* single bytes32 field.
|
|
224
|
+
* @param useSignerToDeriveOffererSignature Derive the offererSignature from the Ethers signer passed into this sdk.
|
|
225
|
+
* @returns The response from the API.
|
|
226
|
+
*/
|
|
227
|
+
async offchainCancelOrder(protocolAddress, orderHash, chain = this.context.chain, offererSignature, useSignerToDeriveOffererSignature) {
|
|
228
|
+
if (useSignerToDeriveOffererSignature) {
|
|
229
|
+
offererSignature = await this.getOffererSignature(protocolAddress, orderHash, chain);
|
|
230
|
+
}
|
|
231
|
+
return this.context.api.offchainCancelOrder(protocolAddress, orderHash, chain, offererSignature);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.CancellationManager = CancellationManager;
|
|
235
|
+
//# sourceMappingURL=cancellation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancellation.js","sourceRoot":"","sources":["../../src/sdk/cancellation.ts"],"names":[],"mappings":";;;AAIA,2CAAkE;AAClE,oCAAgD;AAChD,0CAKuB;AAGvB;;GAEG;AACH,MAAa,mBAAmB;IACV;IAApB,YAAoB,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;IAAG,CAAC;IAE3C;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,WAAW,CAAC,EAChB,KAAK,EACL,SAAS,EACT,cAAc,EACd,eAAe,GAAG,wCAAgC,EAClD,MAAM,GAOP;QACC,iBAAiB;QACjB,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YACzB,MAAM,I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,eAAe,CAAC,CAAA;QAElD,IACE,OAAQ,IAAI,CAAC,OAAO,CAAC,gBAA2B,CAAC,aAAa;YAC9D,WAAW,EACX,CAAC;YACD,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAA;QACH,CAAC;QAED,OAAQ,IAAI,CAAC,OAAO,CAAC,gBAA2B,CAAC,aAAa,CAC5D,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,EAC9D,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,EACvD,EAAE,SAAS,EAAE,CACd,CAAA;IACH,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,mBAAmB,CACvB,eAAuB,EACvB,SAAiB,EACjB,QAAe,IAAI,CAAC,OAAO,CAAC,KAAK,EACjC,gBAAyB,EACzB,iCAA2C;QAE3C,IAAI,iCAAiC,EAAE,CAAC;YACtC,gBAAgB,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAC/C,eAAe,EACf,SAAS,EACT,KAAK,CACN,CAAA;QACH,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CACzC,eAAe,EACf,SAAS,EACT,KAAK,EACL,gBAAgB,CACjB,CAAA;IACH,CAAC;CACF;AAxUD,kDAwUC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
* Shared context passed to all SDK managers.
|
|
7
|
+
* Contains common dependencies and utilities needed across managers.
|
|
8
|
+
*/
|
|
9
|
+
export interface SDKContext {
|
|
10
|
+
/** The blockchain chain being used */
|
|
11
|
+
chain: Chain;
|
|
12
|
+
/** Signer or provider for blockchain interactions */
|
|
13
|
+
signerOrProvider: Signer | JsonRpcProvider;
|
|
14
|
+
/** JSON-RPC provider for read operations */
|
|
15
|
+
provider: JsonRpcProvider;
|
|
16
|
+
/** OpenSea API client */
|
|
17
|
+
api: OpenSeaAPI;
|
|
18
|
+
/** Seaport client instance */
|
|
19
|
+
seaport: Seaport;
|
|
20
|
+
/** Logger function for debugging */
|
|
21
|
+
logger: (msg: string) => void;
|
|
22
|
+
/** Event dispatcher */
|
|
23
|
+
dispatch: (event: EventType, data: EventData) => void;
|
|
24
|
+
/** Transaction confirmation helper */
|
|
25
|
+
confirmTransaction: (hash: string, event: EventType, description: string) => Promise<void>;
|
|
26
|
+
/** Account availability checker */
|
|
27
|
+
requireAccountIsAvailable: (address: string) => Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/sdk/context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { OrderComponents } from "@opensea/seaport-js/lib/types";
|
|
2
|
+
import { type BigNumberish, type Overrides } from "ethers";
|
|
3
|
+
import type { Listing, Offer, Order } from "../api/types";
|
|
4
|
+
import { type OrderV2 } from "../orders/types";
|
|
5
|
+
import { type AssetWithTokenId } from "../types";
|
|
6
|
+
import type { SDKContext } from "./context";
|
|
7
|
+
import type { OrdersManager } from "./orders";
|
|
8
|
+
/**
|
|
9
|
+
* Manager for order fulfillment and validation operations.
|
|
10
|
+
* Handles fulfilling orders, validating orders onchain, and approving orders.
|
|
11
|
+
*/
|
|
12
|
+
export declare class FulfillmentManager {
|
|
13
|
+
private context;
|
|
14
|
+
private ordersManager;
|
|
15
|
+
constructor(context: SDKContext, ordersManager: OrdersManager);
|
|
16
|
+
/**
|
|
17
|
+
* Fulfill a private order for a designated address.
|
|
18
|
+
* @param options
|
|
19
|
+
* @param options.order The order to fulfill
|
|
20
|
+
* @param options.accountAddress Address of the wallet taking the order.
|
|
21
|
+
* @param options.domain An optional domain to be hashed and included at the end of fulfillment calldata.
|
|
22
|
+
* This can be used for onchain order attribution to assist with analytics.
|
|
23
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
24
|
+
* @returns Transaction hash of the order.
|
|
25
|
+
*/
|
|
26
|
+
private fulfillPrivateOrder;
|
|
27
|
+
/**
|
|
28
|
+
* Fulfill an order for an asset. The order can be either a listing or an offer.
|
|
29
|
+
* Uses the OpenSea API to generate fulfillment transaction data and executes it directly.
|
|
30
|
+
* @param options
|
|
31
|
+
* @param options.order The order to fulfill, a.k.a. "take"
|
|
32
|
+
* @param options.accountAddress Address of the wallet taking the offer.
|
|
33
|
+
* @param options.assetContractAddress Optional address of the NFT contract for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
|
|
34
|
+
* @param options.tokenId Optional token ID for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
|
|
35
|
+
* @param options.unitsToFill Optional number of units to fill. Defaults to 1 for both listings and offers.
|
|
36
|
+
* @param options.recipientAddress Optional recipient address for the NFT when fulfilling a listing. Not applicable for offers.
|
|
37
|
+
* @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.
|
|
38
|
+
* @param options.overrides Transaction overrides, ignored if not set.
|
|
39
|
+
* @returns Transaction hash of the order.
|
|
40
|
+
*
|
|
41
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
42
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
43
|
+
* @throws Error if a signer is not provided (read-only providers cannot fulfill orders).
|
|
44
|
+
* @throws Error if the order hash is not available.
|
|
45
|
+
*/
|
|
46
|
+
fulfillOrder({ order, accountAddress, assetContractAddress, tokenId, unitsToFill, recipientAddress, includeOptionalCreatorFees, overrides, }: {
|
|
47
|
+
order: OrderV2 | Order | Listing | Offer;
|
|
48
|
+
accountAddress: string;
|
|
49
|
+
assetContractAddress?: string;
|
|
50
|
+
tokenId?: string;
|
|
51
|
+
unitsToFill?: BigNumberish;
|
|
52
|
+
recipientAddress?: string;
|
|
53
|
+
includeOptionalCreatorFees?: boolean;
|
|
54
|
+
overrides?: Overrides;
|
|
55
|
+
}): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns whether an order is fulfillable.
|
|
58
|
+
* An order may not be fulfillable if a target item's transfer function
|
|
59
|
+
* is locked for some reason, e.g. an item is being rented within a game
|
|
60
|
+
* or trading has been locked for an item type.
|
|
61
|
+
* @param options
|
|
62
|
+
* @param options.order Order to check
|
|
63
|
+
* @param options.accountAddress The account address that will be fulfilling the order
|
|
64
|
+
* @returns True if the order is fulfillable, else False.
|
|
65
|
+
*
|
|
66
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
67
|
+
*/
|
|
68
|
+
isOrderFulfillable({ order, accountAddress, }: {
|
|
69
|
+
order: OrderV2;
|
|
70
|
+
accountAddress: string;
|
|
71
|
+
}): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Instead of signing an off-chain order, this method allows you to approve an order
|
|
74
|
+
* with an onchain transaction.
|
|
75
|
+
* @param order Order to approve
|
|
76
|
+
* @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.
|
|
77
|
+
* @returns Transaction hash of the approval transaction
|
|
78
|
+
*
|
|
79
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
80
|
+
* @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
|
|
81
|
+
*/
|
|
82
|
+
approveOrder(order: OrderV2, domain?: string): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Validates an order onchain using Seaport's validate() method. This submits the order onchain
|
|
85
|
+
* and pre-validates the order using Seaport, which makes it cheaper to fulfill since a signature
|
|
86
|
+
* is not needed to be verified during fulfillment for the order, but is not strictly required
|
|
87
|
+
* and the alternative is orders can be submitted to the API for free instead of sent onchain.
|
|
88
|
+
* @param orderComponents Order components to validate onchain
|
|
89
|
+
* @param accountAddress Address of the wallet that will pay the gas to validate the order
|
|
90
|
+
* @returns Transaction hash of the validation transaction
|
|
91
|
+
*
|
|
92
|
+
* @throws Error if the accountAddress is not available through wallet or provider.
|
|
93
|
+
*/
|
|
94
|
+
validateOrderOnchain(orderComponents: OrderComponents, accountAddress: string): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Create and validate a listing onchain. Combines order building with onchain validation.
|
|
97
|
+
* Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
|
|
98
|
+
* @param options
|
|
99
|
+
* @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
|
|
100
|
+
* @param options.accountAddress Address of the wallet making the listing
|
|
101
|
+
* @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
|
|
102
|
+
* @param options.quantity Number of assets to list. Defaults to 1.
|
|
103
|
+
* @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
|
|
104
|
+
* @param options.salt Arbitrary salt. Auto-generated if not provided.
|
|
105
|
+
* @param options.listingTime When order becomes fulfillable (UTC seconds). Defaults to now.
|
|
106
|
+
* @param options.expirationTime Expiration time (UTC seconds).
|
|
107
|
+
* @param options.buyerAddress Optional buyer restriction. Only this address can purchase.
|
|
108
|
+
* @param options.includeOptionalCreatorFees Include optional creator fees. Default: false.
|
|
109
|
+
* @param options.zone Zone for order protection. Defaults to no zone.
|
|
110
|
+
* @returns Transaction hash
|
|
111
|
+
*
|
|
112
|
+
* @throws Error if asset missing token id or accountAddress unavailable.
|
|
113
|
+
*/
|
|
114
|
+
createListingAndValidateOnchain({ asset, accountAddress, amount, quantity, domain, salt, listingTime, expirationTime, buyerAddress, includeOptionalCreatorFees, zone, }: {
|
|
115
|
+
asset: AssetWithTokenId;
|
|
116
|
+
accountAddress: string;
|
|
117
|
+
amount: BigNumberish;
|
|
118
|
+
quantity?: BigNumberish;
|
|
119
|
+
domain?: string;
|
|
120
|
+
salt?: BigNumberish;
|
|
121
|
+
listingTime?: number;
|
|
122
|
+
expirationTime?: number;
|
|
123
|
+
buyerAddress?: string;
|
|
124
|
+
includeOptionalCreatorFees?: boolean;
|
|
125
|
+
zone?: string;
|
|
126
|
+
}): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Create and validate an offer onchain. Combines order building with onchain validation.
|
|
129
|
+
* Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
|
|
130
|
+
* @param options
|
|
131
|
+
* @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
|
|
132
|
+
* @param options.accountAddress Address of the wallet making the offer.
|
|
133
|
+
* @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
|
|
134
|
+
* @param options.quantity Number of assets to bid for. Defaults to 1.
|
|
135
|
+
* @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
|
|
136
|
+
* @param options.salt Arbitrary salt. Auto-generated if not provided.
|
|
137
|
+
* @param options.expirationTime Expiration time (UTC seconds).
|
|
138
|
+
* @param options.zone Zone for order protection. Defaults to chain's signed zone.
|
|
139
|
+
* @returns Transaction hash
|
|
140
|
+
*
|
|
141
|
+
* @throws Error if asset missing token id or accountAddress unavailable.
|
|
142
|
+
*/
|
|
143
|
+
createOfferAndValidateOnchain({ asset, accountAddress, amount, quantity, domain, salt, expirationTime, zone, }: {
|
|
144
|
+
asset: AssetWithTokenId;
|
|
145
|
+
accountAddress: string;
|
|
146
|
+
amount: BigNumberish;
|
|
147
|
+
quantity?: BigNumberish;
|
|
148
|
+
domain?: string;
|
|
149
|
+
salt?: BigNumberish;
|
|
150
|
+
expirationTime?: BigNumberish;
|
|
151
|
+
zone?: string;
|
|
152
|
+
}): Promise<string>;
|
|
153
|
+
}
|