opensea-js
Version:
TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data
127 lines • 4.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeOrder = exports.serializeOrdersQueryOptions = exports.getFulfillOfferPayload = exports.getFulfillListingPayload = exports.getFulfillmentDataPath = exports.getBuildCollectionOfferPayload = exports.getPostCollectionOfferPayload = exports.DEFAULT_SEAPORT_CONTRACT_ADDRESS = void 0;
const constants_1 = require("@opensea/seaport-js/lib/constants");
const types_1 = require("../types");
const utils_1 = require("../utils");
exports.DEFAULT_SEAPORT_CONTRACT_ADDRESS = constants_1.CROSS_CHAIN_SEAPORT_V1_6_ADDRESS;
const getPostCollectionOfferPayload = (collectionSlug, protocol_data, traitType, traitValue) => {
const payload = {
criteria: {
collection: { slug: collectionSlug },
},
protocol_data,
protocol_address: exports.DEFAULT_SEAPORT_CONTRACT_ADDRESS,
};
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, traitType, traitValue) => {
const payload = {
offerer: offererAddress,
quantity,
criteria: {
collection: {
slug: collectionSlug,
},
},
protocol_address: exports.DEFAULT_SEAPORT_CONTRACT_ADDRESS,
offer_protection_enabled: offerProtectionEnabled,
};
if (traitType && traitValue) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
payload.criteria.trait = {
type: traitType,
value: traitValue,
};
}
return payload;
};
exports.getBuildCollectionOfferPayload = getBuildCollectionOfferPayload;
const getFulfillmentDataPath = (side) => {
const sidePath = side === types_1.OrderSide.LISTING ? "listings" : "offers";
return `/v2/${sidePath}/fulfillment_data`;
};
exports.getFulfillmentDataPath = getFulfillmentDataPath;
const getFulfillListingPayload = (fulfillerAddress, order_hash, protocolAddress, chain) => {
return {
listing: {
hash: order_hash,
chain,
protocol_address: protocolAddress,
},
fulfiller: {
address: fulfillerAddress,
},
};
};
exports.getFulfillListingPayload = getFulfillListingPayload;
const getFulfillOfferPayload = (fulfillerAddress, order_hash, protocolAddress, chain) => {
return {
offer: {
hash: order_hash,
chain,
protocol_address: protocolAddress,
},
fulfiller: {
address: fulfillerAddress,
},
};
};
exports.getFulfillOfferPayload = getFulfillOfferPayload;
const serializeOrdersQueryOptions = (options) => {
return {
limit: options.limit,
cursor: options.cursor,
payment_token_address: options.paymentTokenAddress,
maker: options.maker,
taker: options.taker,
owner: options.owner,
listed_after: options.listedAfter,
listed_before: options.listedBefore,
token_ids: options.tokenIds ?? [options.tokenId],
asset_contract_address: options.assetContractAddress,
order_by: options.orderBy,
order_direction: options.orderDirection,
only_english: options.onlyEnglish,
};
};
exports.serializeOrdersQueryOptions = serializeOrdersQueryOptions;
const deserializeOrder = (order) => {
return {
createdDate: order.created_date,
closingDate: order.closing_date,
listingTime: order.listing_time,
expirationTime: order.expiration_time,
orderHash: order.order_hash,
maker: (0, utils_1.accountFromJSON)(order.maker),
taker: order.taker ? (0, utils_1.accountFromJSON)(order.taker) : null,
protocolData: order.protocol_data,
protocolAddress: order.protocol_address,
currentPrice: BigInt(order.current_price),
makerFees: order.maker_fees.map(({ account, basis_points }) => ({
account: (0, utils_1.accountFromJSON)(account),
basisPoints: basis_points,
})),
takerFees: order.taker_fees.map(({ account, basis_points }) => ({
account: (0, utils_1.accountFromJSON)(account),
basisPoints: basis_points,
})),
side: order.side,
orderType: order.order_type,
cancelled: order.cancelled,
finalized: order.finalized,
markedInvalid: order.marked_invalid,
clientSignature: order.client_signature,
remainingQuantity: order.remaining_quantity,
};
};
exports.deserializeOrder = deserializeOrder;
//# sourceMappingURL=utils.js.map