opensea-js
Advanced tools
Comparing version 7.1.2 to 7.1.3
@@ -129,5 +129,7 @@ import { BuildOfferResponse, ListNFTsResponse, GetNFTResponse, ListCollectionOffersResponse, GetOrdersResponse, GetBestOfferResponse, GetBestListingResponse, GetOffersResponse, GetListingsResponse, CollectionOffer } from "./types"; | ||
* @param offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading. | ||
* @param traitType If defined, the trait name to create the collection offer for. | ||
* @param traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link BuildOfferResponse} returned by the API. | ||
*/ | ||
buildOffer(offererAddress: string, quantity: number, collectionSlug: string, offerProtectionEnabled?: boolean): Promise<BuildOfferResponse>; | ||
buildOffer(offererAddress: string, quantity: number, collectionSlug: string, offerProtectionEnabled?: boolean, traitType?: string, traitValue?: string): Promise<BuildOfferResponse>; | ||
/** | ||
@@ -143,5 +145,7 @@ * Get a list collection offers for a given slug. | ||
* @param slug The slug (identifier) of the collection to post the offer for. | ||
* @param traitType If defined, the trait name to create the collection offer for. | ||
* @param traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link Offer} returned to the API. | ||
*/ | ||
postCollectionOffer(order: ProtocolData, slug: string): Promise<CollectionOffer | null>; | ||
postCollectionOffer(order: ProtocolData, slug: string, traitType?: string, traitValue?: string): Promise<CollectionOffer | null>; | ||
/** | ||
@@ -148,0 +152,0 @@ * Fetch multiple NFTs for a collection. |
@@ -201,6 +201,13 @@ "use strict"; | ||
* @param offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading. | ||
* @param traitType If defined, the trait name to create the collection offer for. | ||
* @param traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link BuildOfferResponse} returned by the API. | ||
*/ | ||
async buildOffer(offererAddress, quantity, collectionSlug, offerProtectionEnabled = true) { | ||
const payload = (0, utils_1.getBuildCollectionOfferPayload)(offererAddress, quantity, collectionSlug, offerProtectionEnabled); | ||
async buildOffer(offererAddress, quantity, collectionSlug, offerProtectionEnabled = true, traitType, traitValue) { | ||
if (traitType || traitValue) { | ||
if (!traitType || !traitValue) { | ||
throw new Error("Both traitType and traitValue must be defined if one is defined."); | ||
} | ||
} | ||
const payload = (0, utils_1.getBuildCollectionOfferPayload)(offererAddress, quantity, collectionSlug, offerProtectionEnabled, traitType, traitValue); | ||
const response = await this.post((0, apiPaths_1.getBuildOfferPath)(), payload); | ||
@@ -221,6 +228,8 @@ return response; | ||
* @param slug The slug (identifier) of the collection to post the offer for. | ||
* @param traitType If defined, the trait name to create the collection offer for. | ||
* @param traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link Offer} returned to the API. | ||
*/ | ||
async postCollectionOffer(order, slug) { | ||
const payload = (0, utils_1.getPostCollectionOfferPayload)(slug, order); | ||
async postCollectionOffer(order, slug, traitType, traitValue) { | ||
const payload = (0, utils_1.getPostCollectionOfferPayload)(slug, order, traitType, traitValue); | ||
return await this.post((0, apiPaths_1.getPostCollectionOfferPath)(), payload); | ||
@@ -407,3 +416,7 @@ } | ||
if (errors?.length > 0) { | ||
throw new Error(`Server Error: ${errors.join(", ")}`); | ||
let errorMessage = errors.join(", "); | ||
if (errorMessage === "[object Object]") { | ||
errorMessage = JSON.stringify(errors); | ||
} | ||
throw new Error(`Server Error: ${errorMessage}`); | ||
} | ||
@@ -410,0 +423,0 @@ else { |
import { OrdersQueryOptions, OrderV2, SerializedOrderV2, ProtocolData } from "./types"; | ||
import { Chain, OrderSide } from "../types"; | ||
export declare const DEFAULT_SEAPORT_CONTRACT_ADDRESS = "0x0000000000000068F116a894984e2DB1123eB395"; | ||
export declare const getPostCollectionOfferPayload: (collectionSlug: string, protocol_data: ProtocolData) => { | ||
export declare const getPostCollectionOfferPayload: (collectionSlug: string, protocol_data: ProtocolData, traitType?: string, traitValue?: string) => { | ||
criteria: { | ||
@@ -13,3 +13,3 @@ collection: { | ||
}; | ||
export declare const getBuildCollectionOfferPayload: (offererAddress: string, quantity: number, collectionSlug: string, offerProtectionEnabled: boolean) => { | ||
export declare const getBuildCollectionOfferPayload: (offererAddress: string, quantity: number, collectionSlug: string, offerProtectionEnabled: boolean, traitType?: string, traitValue?: string) => { | ||
offerer: string; | ||
@@ -16,0 +16,0 @@ quantity: number; |
@@ -8,4 +8,4 @@ "use strict"; | ||
exports.DEFAULT_SEAPORT_CONTRACT_ADDRESS = constants_1.CROSS_CHAIN_SEAPORT_V1_6_ADDRESS; | ||
const getPostCollectionOfferPayload = (collectionSlug, protocol_data) => { | ||
return { | ||
const getPostCollectionOfferPayload = (collectionSlug, protocol_data, traitType, traitValue) => { | ||
const payload = { | ||
criteria: { | ||
@@ -17,6 +17,14 @@ collection: { slug: collectionSlug }, | ||
}; | ||
if (traitType && traitValue) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
payload.criteria.trait = { | ||
type: traitType, | ||
value: traitValue, | ||
}; | ||
} | ||
return payload; | ||
}; | ||
exports.getPostCollectionOfferPayload = getPostCollectionOfferPayload; | ||
const getBuildCollectionOfferPayload = (offererAddress, quantity, collectionSlug, offerProtectionEnabled) => { | ||
return { | ||
const getBuildCollectionOfferPayload = (offererAddress, quantity, collectionSlug, offerProtectionEnabled, traitType, traitValue) => { | ||
const payload = { | ||
offerer: offererAddress, | ||
@@ -32,2 +40,10 @@ quantity, | ||
}; | ||
if (traitType && traitValue) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
payload.criteria.trait = { | ||
type: traitType, | ||
value: traitValue, | ||
}; | ||
} | ||
return payload; | ||
}; | ||
@@ -34,0 +50,0 @@ exports.getBuildCollectionOfferPayload = getBuildCollectionOfferPayload; |
@@ -161,5 +161,8 @@ import { Seaport } from "@opensea/seaport-js"; | ||
* @param options.excludeOptionalCreatorFees If true, optional creator fees will be excluded from the offer. Default: false. | ||
* @param options.offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading. | ||
* @param options.traitType If defined, the trait name to create the collection offer for. | ||
* @param options.traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link CollectionOffer} that was created. | ||
*/ | ||
createCollectionOffer({ collectionSlug, accountAddress, amount, quantity, domain, salt, expirationTime, paymentTokenAddress, excludeOptionalCreatorFees, }: { | ||
createCollectionOffer({ collectionSlug, accountAddress, amount, quantity, domain, salt, expirationTime, paymentTokenAddress, excludeOptionalCreatorFees, offerProtectionEnabled, traitType, traitValue, }: { | ||
collectionSlug: string; | ||
@@ -174,2 +177,5 @@ accountAddress: string; | ||
excludeOptionalCreatorFees?: boolean; | ||
offerProtectionEnabled?: boolean; | ||
traitType?: string; | ||
traitValue?: string; | ||
}): Promise<CollectionOffer | null>; | ||
@@ -176,0 +182,0 @@ /** |
@@ -208,2 +208,6 @@ "use strict"; | ||
}); | ||
let zone = constants_2.DEFAULT_ZONE; | ||
if (collection.requiredZone) { | ||
zone = collection.requiredZone; | ||
} | ||
const { executeAllActions } = await this.seaport_v1_6.createOrder({ | ||
@@ -220,6 +224,6 @@ offer: [ | ||
: (0, utils_2.getMaxOrderExpirationTimestamp)().toString(), | ||
zone: constants_2.DEFAULT_ZONE, | ||
zone, | ||
domain, | ||
salt: BigInt(salt ?? 0).toString(), | ||
restrictedByZone: false, | ||
restrictedByZone: zone !== constants_2.DEFAULT_ZONE, | ||
allowPartialFills: true, | ||
@@ -277,2 +281,14 @@ }, accountAddress); | ||
} | ||
let zone = constants_2.DEFAULT_ZONE; | ||
if (englishAuction) { | ||
if ((0, utils_2.isTestChain)(this.chain)) { | ||
zone = constants_2.ENGLISH_AUCTION_ZONE_TESTNETS; | ||
} | ||
else { | ||
zone = constants_2.ENGLISH_AUCTION_ZONE_MAINNETS; | ||
} | ||
} | ||
else if (collection.requiredZone) { | ||
zone = collection.requiredZone; | ||
} | ||
const { executeAllActions } = await this.seaport_v1_6.createOrder({ | ||
@@ -284,10 +300,6 @@ offer: offerAssetItems, | ||
(0, utils_2.getMaxOrderExpirationTimestamp)().toString(), | ||
zone: englishAuction | ||
? (0, utils_2.isTestChain)(this.chain) | ||
? constants_2.ENGLISH_AUCTION_ZONE_TESTNETS | ||
: constants_2.ENGLISH_AUCTION_ZONE_MAINNETS | ||
: constants_2.DEFAULT_ZONE, | ||
zone, | ||
domain, | ||
salt: BigInt(salt ?? 0).toString(), | ||
restrictedByZone: englishAuction ? true : false, | ||
restrictedByZone: zone !== constants_2.DEFAULT_ZONE, | ||
allowPartialFills: englishAuction ? false : true, | ||
@@ -314,8 +326,11 @@ }, accountAddress); | ||
* @param options.excludeOptionalCreatorFees If true, optional creator fees will be excluded from the offer. Default: false. | ||
* @param options.offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading. | ||
* @param options.traitType If defined, the trait name to create the collection offer for. | ||
* @param options.traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link CollectionOffer} that was created. | ||
*/ | ||
async createCollectionOffer({ collectionSlug, accountAddress, amount, quantity, domain, salt, expirationTime, paymentTokenAddress = (0, utils_2.getWETHAddress)(this.chain), excludeOptionalCreatorFees = false, }) { | ||
async createCollectionOffer({ collectionSlug, accountAddress, amount, quantity, domain, salt, expirationTime, paymentTokenAddress = (0, utils_2.getWETHAddress)(this.chain), excludeOptionalCreatorFees = false, offerProtectionEnabled = true, traitType, traitValue, }) { | ||
await this._requireAccountIsAvailable(accountAddress); | ||
const collection = await this.api.getCollection(collectionSlug); | ||
const buildOfferResult = await this.api.buildOffer(accountAddress, quantity, collectionSlug); | ||
const buildOfferResult = await this.api.buildOffer(accountAddress, quantity, collectionSlug, offerProtectionEnabled, traitType, traitValue); | ||
const item = buildOfferResult.partialParameters.consideration[0]; | ||
@@ -359,3 +374,3 @@ const convertedConsiderationItem = { | ||
const order = await executeAllActions(); | ||
return this.api.postCollectionOffer(order, collectionSlug); | ||
return this.api.postCollectionOffer(order, collectionSlug, traitType, traitValue); | ||
} | ||
@@ -362,0 +377,0 @@ /** |
@@ -303,2 +303,4 @@ import { BigNumberish } from "ethers"; | ||
createdDate: string; | ||
/** When defined, the zone required for orders for the collection */ | ||
requiredZone?: string; | ||
} | ||
@@ -305,0 +307,0 @@ /** |
@@ -40,2 +40,3 @@ "use strict"; | ||
createdDate: collection.created_date, | ||
requiredZone: collection.required_zone, | ||
}; | ||
@@ -42,0 +43,0 @@ }; |
{ | ||
"name": "opensea-js", | ||
"version": "7.1.2", | ||
"version": "7.1.3", | ||
"description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -358,2 +358,4 @@ import { ethers } from "ethers"; | ||
* @param offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading. | ||
* @param traitType If defined, the trait name to create the collection offer for. | ||
* @param traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link BuildOfferResponse} returned by the API. | ||
@@ -366,3 +368,12 @@ */ | ||
offerProtectionEnabled = true, | ||
traitType?: string, | ||
traitValue?: string, | ||
): Promise<BuildOfferResponse> { | ||
if (traitType || traitValue) { | ||
if (!traitType || !traitValue) { | ||
throw new Error( | ||
"Both traitType and traitValue must be defined if one is defined.", | ||
); | ||
} | ||
} | ||
const payload = getBuildCollectionOfferPayload( | ||
@@ -373,2 +384,4 @@ offererAddress, | ||
offerProtectionEnabled, | ||
traitType, | ||
traitValue, | ||
); | ||
@@ -399,2 +412,4 @@ const response = await this.post<BuildOfferResponse>( | ||
* @param slug The slug (identifier) of the collection to post the offer for. | ||
* @param traitType If defined, the trait name to create the collection offer for. | ||
* @param traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link Offer} returned to the API. | ||
@@ -405,4 +420,11 @@ */ | ||
slug: string, | ||
traitType?: string, | ||
traitValue?: string, | ||
): Promise<CollectionOffer | null> { | ||
const payload = getPostCollectionOfferPayload(slug, order); | ||
const payload = getPostCollectionOfferPayload( | ||
slug, | ||
order, | ||
traitType, | ||
traitValue, | ||
); | ||
return await this.post<CollectionOffer>( | ||
@@ -664,3 +686,7 @@ getPostCollectionOfferPath(), | ||
if (errors?.length > 0) { | ||
throw new Error(`Server Error: ${errors.join(", ")}`); | ||
let errorMessage = errors.join(", "); | ||
if (errorMessage === "[object Object]") { | ||
errorMessage = JSON.stringify(errors); | ||
} | ||
throw new Error(`Server Error: ${errorMessage}`); | ||
} else { | ||
@@ -667,0 +693,0 @@ // Otherwise, let ethers throw a SERVER_ERROR since it will include |
@@ -17,4 +17,6 @@ import { CROSS_CHAIN_SEAPORT_V1_6_ADDRESS } from "@opensea/seaport-js/lib/constants"; | ||
protocol_data: ProtocolData, | ||
traitType?: string, | ||
traitValue?: string, | ||
) => { | ||
return { | ||
const payload = { | ||
criteria: { | ||
@@ -26,2 +28,10 @@ collection: { slug: collectionSlug }, | ||
}; | ||
if (traitType && traitValue) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(payload.criteria as any).trait = { | ||
type: traitType, | ||
value: traitValue, | ||
}; | ||
} | ||
return payload; | ||
}; | ||
@@ -34,4 +44,6 @@ | ||
offerProtectionEnabled: boolean, | ||
traitType?: string, | ||
traitValue?: string, | ||
) => { | ||
return { | ||
const payload = { | ||
offerer: offererAddress, | ||
@@ -47,2 +59,10 @@ quantity, | ||
}; | ||
if (traitType && traitValue) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(payload.criteria as any).trait = { | ||
type: traitType, | ||
value: traitValue, | ||
}; | ||
} | ||
return payload; | ||
}; | ||
@@ -49,0 +69,0 @@ |
@@ -396,2 +396,7 @@ import EventEmitter = require("events"); | ||
let zone = DEFAULT_ZONE; | ||
if (collection.requiredZone) { | ||
zone = collection.requiredZone; | ||
} | ||
const { executeAllActions } = await this.seaport_v1_6.createOrder( | ||
@@ -410,6 +415,6 @@ { | ||
: getMaxOrderExpirationTimestamp().toString(), | ||
zone: DEFAULT_ZONE, | ||
zone, | ||
domain, | ||
salt: BigInt(salt ?? 0).toString(), | ||
restrictedByZone: false, | ||
restrictedByZone: zone !== DEFAULT_ZONE, | ||
allowPartialFills: true, | ||
@@ -516,2 +521,13 @@ }, | ||
let zone = DEFAULT_ZONE; | ||
if (englishAuction) { | ||
if (isTestChain(this.chain)) { | ||
zone = ENGLISH_AUCTION_ZONE_TESTNETS; | ||
} else { | ||
zone = ENGLISH_AUCTION_ZONE_MAINNETS; | ||
} | ||
} else if (collection.requiredZone) { | ||
zone = collection.requiredZone; | ||
} | ||
const { executeAllActions } = await this.seaport_v1_6.createOrder( | ||
@@ -525,10 +541,6 @@ { | ||
getMaxOrderExpirationTimestamp().toString(), | ||
zone: englishAuction | ||
? isTestChain(this.chain) | ||
? ENGLISH_AUCTION_ZONE_TESTNETS | ||
: ENGLISH_AUCTION_ZONE_MAINNETS | ||
: DEFAULT_ZONE, | ||
zone, | ||
domain, | ||
salt: BigInt(salt ?? 0).toString(), | ||
restrictedByZone: englishAuction ? true : false, | ||
restrictedByZone: zone !== DEFAULT_ZONE, | ||
allowPartialFills: englishAuction ? false : true, | ||
@@ -559,2 +571,5 @@ }, | ||
* @param options.excludeOptionalCreatorFees If true, optional creator fees will be excluded from the offer. Default: false. | ||
* @param options.offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading. | ||
* @param options.traitType If defined, the trait name to create the collection offer for. | ||
* @param options.traitValue If defined, the trait value to create the collection offer for. | ||
* @returns The {@link CollectionOffer} that was created. | ||
@@ -572,2 +587,5 @@ */ | ||
excludeOptionalCreatorFees = false, | ||
offerProtectionEnabled = true, | ||
traitType, | ||
traitValue, | ||
}: { | ||
@@ -583,2 +601,5 @@ collectionSlug: string; | ||
excludeOptionalCreatorFees?: boolean; | ||
offerProtectionEnabled?: boolean; | ||
traitType?: string; | ||
traitValue?: string; | ||
}): Promise<CollectionOffer | null> { | ||
@@ -592,2 +613,5 @@ await this._requireAccountIsAvailable(accountAddress); | ||
collectionSlug, | ||
offerProtectionEnabled, | ||
traitType, | ||
traitValue, | ||
); | ||
@@ -646,3 +670,8 @@ const item = buildOfferResult.partialParameters.consideration[0]; | ||
return this.api.postCollectionOffer(order, collectionSlug); | ||
return this.api.postCollectionOffer( | ||
order, | ||
collectionSlug, | ||
traitType, | ||
traitValue, | ||
); | ||
} | ||
@@ -649,0 +678,0 @@ |
@@ -319,2 +319,4 @@ import { BigNumberish } from "ethers"; | ||
createdDate: string; | ||
/** When defined, the zone required for orders for the collection */ | ||
requiredZone?: string; | ||
} | ||
@@ -321,0 +323,0 @@ |
@@ -55,2 +55,3 @@ import { | ||
createdDate: collection.created_date, | ||
requiredZone: collection.required_zone, | ||
}; | ||
@@ -57,0 +58,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
485292
12086