From 760ee9885e087995f5a2b90bbc40130281832207 Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Fri, 12 Jul 2024 11:18:23 -0700 Subject: [PATCH] add zone parameter to createListing, make default zone ZeroAddress (#1517) * make default zone ZeroAddress, add zone parameter to createListing * bump version --- package.json | 2 +- src/constants.ts | 5 +++-- src/sdk.ts | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 0d99dcf2c..ea65b726a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opensea-js", - "version": "7.1.11", + "version": "7.1.12", "description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data", "license": "MIT", "author": "OpenSea Developers", diff --git a/src/constants.ts b/src/constants.ts index 1b5bd822c..aa13b6b5f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,4 @@ -import { FixedNumber, ZeroAddress } from "ethers"; +import { FixedNumber } from "ethers"; export const FIXED_NUMBER_100 = FixedNumber.fromValue(100); export const INVERSE_BASIS_POINT = 10_000n; // 100 basis points per 1% @@ -7,8 +7,9 @@ export const MAX_EXPIRATION_MONTHS = 1; export const API_BASE_MAINNET = "https://api.opensea.io"; export const API_BASE_TESTNET = "https://testnets-api.opensea.io"; -export const DEFAULT_ZONE = ZeroAddress; +// eslint-disable-next-line import/no-unused-modules export const SIGNED_ZONE = "0x000056f7000000ece9003ca63978907a00ffd100"; + export const ENGLISH_AUCTION_ZONE_MAINNETS = "0x110b2b128a9ed1be5ef3232d8e4e41640df5c2cd"; export const ENGLISH_AUCTION_ZONE_TESTNETS = diff --git a/src/sdk.ts b/src/sdk.ts index e78f60293..59ad1723f 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -21,13 +21,12 @@ import { parseEther, JsonRpcProvider, ContractTransactionResponse, + ZeroAddress, } from "ethers"; import { OpenSeaAPI } from "./api/api"; import { CollectionOffer, Listing, NFT, Order } from "./api/types"; import { INVERSE_BASIS_POINT, - DEFAULT_ZONE, - SIGNED_ZONE, ENGLISH_AUCTION_ZONE_MAINNETS, ENGLISH_AUCTION_ZONE_TESTNETS, } from "./constants"; @@ -343,7 +342,8 @@ export class OpenSeaSDK { * @param options.expirationTime Expiration time for the order, in UTC seconds * @param options.paymentTokenAddress ERC20 address for the payment token in the order. If unspecified, defaults to WETH * @param options.excludeOptionalCreatorFees If true, optional creator fees will be excluded from the offer. Default: false. - * @param options.zone The zone to use for the order. If unspecified, defaults to SIGNED_ZONE. + * @param options.zone The zone to use for the order. For order protection, pass SIGNED_ZONE. If unspecified, defaults to no zone. + * * @returns The {@link OrderV2} that was created. * * @throws Error if the asset does not contain a token id. @@ -361,7 +361,7 @@ export class OpenSeaSDK { expirationTime, paymentTokenAddress = getWETHAddress(this.chain), excludeOptionalCreatorFees = false, - zone = SIGNED_ZONE, // Add the zone parameter with default value SIGNED_ZONE + zone = ZeroAddress, }: { asset: AssetWithTokenId; accountAddress: string; @@ -372,7 +372,7 @@ export class OpenSeaSDK { expirationTime?: BigNumberish; paymentTokenAddress?: string; excludeOptionalCreatorFees?: boolean; - zone?: string; // Add the zone type + zone?: string; }): Promise { await this._requireAccountIsAvailable(accountAddress); @@ -418,7 +418,7 @@ export class OpenSeaSDK { zone, domain, salt: BigInt(salt ?? 0).toString(), - restrictedByZone: zone !== DEFAULT_ZONE, + restrictedByZone: zone !== ZeroAddress, allowPartialFills: true, }, accountAddress, @@ -448,6 +448,7 @@ export class OpenSeaSDK { * @param options.buyerAddress Optional address that's allowed to purchase this item. If specified, no other address will be able to take the order, unless its value is the null address. * @param options.englishAuction If true, the order will be listed as an English auction. * @param options.excludeOptionalCreatorFees If true, optional creator fees will be excluded from the listing. Default: false. + * @param options.zone The zone to use for the order. For order protection, pass SIGNED_ZONE. If unspecified, defaults to no zone. * @returns The {@link OrderV2} that was created. * * @throws Error if the asset does not contain a token id. @@ -469,6 +470,7 @@ export class OpenSeaSDK { buyerAddress, englishAuction, excludeOptionalCreatorFees = false, + zone = ZeroAddress, }: { asset: AssetWithTokenId; accountAddress: string; @@ -483,6 +485,7 @@ export class OpenSeaSDK { buyerAddress?: string; englishAuction?: boolean; excludeOptionalCreatorFees?: boolean; + zone?: string; }): Promise { await this._requireAccountIsAvailable(accountAddress); @@ -520,13 +523,10 @@ export class OpenSeaSDK { ); } - let zone = DEFAULT_ZONE; if (englishAuction) { - if (isTestChain(this.chain)) { - zone = ENGLISH_AUCTION_ZONE_TESTNETS; - } else { - zone = ENGLISH_AUCTION_ZONE_MAINNETS; - } + zone = isTestChain(this.chain) + ? ENGLISH_AUCTION_ZONE_TESTNETS + : ENGLISH_AUCTION_ZONE_MAINNETS; } else if (collection.requiredZone) { zone = collection.requiredZone; } @@ -542,7 +542,7 @@ export class OpenSeaSDK { zone, domain, salt: BigInt(salt ?? 0).toString(), - restrictedByZone: zone !== DEFAULT_ZONE, + restrictedByZone: zone !== ZeroAddress, allowPartialFills: englishAuction ? false : true, }, accountAddress,