From ab9a8cbb0f1e1129dd99dd1b309d3fa7f7329522 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Wed, 29 Nov 2023 06:17:38 -0500 Subject: [PATCH 1/8] Update --- .changeset/calm-ads-change.md | 5 ++ packages/sdk/src/evm/common/deploy.ts | 48 ++++++++++--- .../src/evm/common/override-fee-recipient.ts | 19 +++++ packages/sdk/src/evm/core/classes/factory.ts | 70 ++++++++++++++----- packages/sdk/src/evm/core/sdk.ts | 1 - 5 files changed, 113 insertions(+), 30 deletions(-) create mode 100644 .changeset/calm-ads-change.md create mode 100644 packages/sdk/src/evm/common/override-fee-recipient.ts diff --git a/.changeset/calm-ads-change.md b/.changeset/calm-ads-change.md new file mode 100644 index 00000000000..a7cbfbcb87e --- /dev/null +++ b/.changeset/calm-ads-change.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/sdk": patch +--- + +Fix deploy issue "invalid recipient" diff --git a/packages/sdk/src/evm/common/deploy.ts b/packages/sdk/src/evm/common/deploy.ts index feca873c78c..dad7ac7c4fd 100644 --- a/packages/sdk/src/evm/common/deploy.ts +++ b/packages/sdk/src/evm/common/deploy.ts @@ -14,7 +14,7 @@ import { MarketplaceInitializer, MarketplaceV3Initializer, } from "../contracts"; -import { BigNumber, Signer, providers } from "ethers"; +import { BigNumber, Signer, constants, providers } from "ethers"; import { z } from "zod"; import { ThirdwebStorage } from "@thirdweb-dev/storage"; import { SUPPORTED_CHAIN_IDS } from "../constants/chains/SUPPORTED_CHAIN_IDS"; @@ -23,6 +23,7 @@ import type { PrebuiltContractType, DeploySchemaForPrebuiltContractType, } from "../contracts"; +import { overrideFeeRecipient } from "./override-fee-recipient"; /** * @@ -74,11 +75,17 @@ export async function getDeployArguments< erc721metadata.symbol, contractURI, trustedForwarders, - erc721metadata.primary_sale_recipient, + overrideFeeRecipient( + signerAddress, + erc721metadata.primary_sale_recipient, + ), erc721metadata.fee_recipient, erc721metadata.seller_fee_basis_points, erc721metadata.platform_fee_basis_points, - erc721metadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + erc721metadata.platform_fee_recipient, + ), ]; case SignatureDropInitializer.contractType: const signatureDropmetadata = @@ -89,11 +96,17 @@ export async function getDeployArguments< signatureDropmetadata.symbol, contractURI, trustedForwarders, - signatureDropmetadata.primary_sale_recipient, + overrideFeeRecipient( + signerAddress, + signatureDropmetadata.primary_sale_recipient, + ), signatureDropmetadata.fee_recipient, signatureDropmetadata.seller_fee_basis_points, signatureDropmetadata.platform_fee_basis_points, - signatureDropmetadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + signatureDropmetadata.platform_fee_recipient, + ), ]; case MultiwrapInitializer.contractType: const multiwrapMetadata = @@ -117,11 +130,17 @@ export async function getDeployArguments< erc1155metadata.symbol, contractURI, trustedForwarders, - erc1155metadata.primary_sale_recipient, + overrideFeeRecipient( + signerAddress, + erc1155metadata.primary_sale_recipient, + ), erc1155metadata.fee_recipient, erc1155metadata.seller_fee_basis_points, erc1155metadata.platform_fee_basis_points, - erc1155metadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + erc1155metadata.platform_fee_recipient, + ), ]; case TokenDropInitializer.contractType: case TokenInitializer.contractType: @@ -134,8 +153,14 @@ export async function getDeployArguments< erc20metadata.symbol, contractURI, trustedForwarders, - erc20metadata.primary_sale_recipient, - erc20metadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + erc20metadata.primary_sale_recipient, + ), + overrideFeeRecipient( + signerAddress, + erc20metadata.platform_fee_recipient, + ), erc20metadata.platform_fee_basis_points, ]; case VoteInitializer.contractType: @@ -171,7 +196,10 @@ export async function getDeployArguments< signerAddress, contractURI, trustedForwarders, - marketplaceMetadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + marketplaceMetadata.platform_fee_recipient, + ), marketplaceMetadata.platform_fee_basis_points, ]; case PackInitializer.contractType: diff --git a/packages/sdk/src/evm/common/override-fee-recipient.ts b/packages/sdk/src/evm/common/override-fee-recipient.ts new file mode 100644 index 00000000000..4997244fa3f --- /dev/null +++ b/packages/sdk/src/evm/common/override-fee-recipient.ts @@ -0,0 +1,19 @@ +import { constants } from "ethers"; + +/** + * In the past we default `platform_fee_recipient` and `primary_sale_recipient` to AddressZero. + * However due to a recent change in our smart contract extensions (PrimarySale & PlatformFee), AddressZero is no longer an accepted value for those fields. + * So now we're set the default value to the signer address. + * @reference https://github.com/thirdweb-dev/contracts/pull/530 + * @param signerAddress The address of the contract deployer + * @param fee_recipient The address that will receive the platform fees and/or sale fees + * @returns `signerAddress` if the `fee_recipient` is AddressZero, otherwise returns `fee_recipient` + * @internal + */ +export function overrideFeeRecipient( + signerAddress: string, + fee_recipient: string, +): string { + if (fee_recipient === constants.AddressZero) return signerAddress; + return fee_recipient; +} diff --git a/packages/sdk/src/evm/core/classes/factory.ts b/packages/sdk/src/evm/core/classes/factory.ts index c5f46150a52..d0a84c355dd 100644 --- a/packages/sdk/src/evm/core/classes/factory.ts +++ b/packages/sdk/src/evm/core/classes/factory.ts @@ -42,6 +42,7 @@ import type { DeployEvents } from "../../types/deploy/deploy-events"; import { NetworkInput } from "../types"; import { ContractWrapper } from "./contract-wrapper"; import { Transaction } from "./transactions"; +import { overrideFeeRecipient } from "../../common/override-fee-recipient"; /** * @internal @@ -233,43 +234,56 @@ export class ContractFactory extends ContractWrapper { if (metadata.trusted_forwarders && metadata.trusted_forwarders.length > 0) { trustedForwarders = metadata.trusted_forwarders; } + const signerAddress = await this.getSignerAddress(); switch (contractType) { case NFTDropInitializer.contractType: case NFTCollectionInitializer.contractType: const erc721metadata = await NFTDropInitializer.schema.deploy.parseAsync(metadata); return [ - await this.getSignerAddress(), + signerAddress, erc721metadata.name, erc721metadata.symbol, contractURI, trustedForwarders, - erc721metadata.primary_sale_recipient, + overrideFeeRecipient( + signerAddress, + erc721metadata.primary_sale_recipient, + ), erc721metadata.fee_recipient, erc721metadata.seller_fee_basis_points, erc721metadata.platform_fee_basis_points, - erc721metadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + erc721metadata.platform_fee_recipient, + ), ]; case SignatureDropInitializer.contractType: const signatureDropmetadata = await SignatureDropInitializer.schema.deploy.parseAsync(metadata); return [ - await this.getSignerAddress(), + signerAddress, signatureDropmetadata.name, signatureDropmetadata.symbol, contractURI, trustedForwarders, - signatureDropmetadata.primary_sale_recipient, + overrideFeeRecipient( + signerAddress, + signatureDropmetadata.primary_sale_recipient, + ), signatureDropmetadata.fee_recipient, signatureDropmetadata.seller_fee_basis_points, signatureDropmetadata.platform_fee_basis_points, - signatureDropmetadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + signatureDropmetadata.platform_fee_recipient, + ), ]; case MultiwrapInitializer.contractType: const multiwrapMetadata = await MultiwrapInitializer.schema.deploy.parseAsync(metadata); return [ - await this.getSignerAddress(), + signerAddress, multiwrapMetadata.name, multiwrapMetadata.symbol, contractURI, @@ -282,16 +296,22 @@ export class ContractFactory extends ContractWrapper { const erc1155metadata = await EditionDropInitializer.schema.deploy.parseAsync(metadata); return [ - await this.getSignerAddress(), + signerAddress, erc1155metadata.name, erc1155metadata.symbol, contractURI, trustedForwarders, - erc1155metadata.primary_sale_recipient, + overrideFeeRecipient( + signerAddress, + erc1155metadata.primary_sale_recipient, + ), erc1155metadata.fee_recipient, erc1155metadata.seller_fee_basis_points, erc1155metadata.platform_fee_basis_points, - erc1155metadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + erc1155metadata.platform_fee_recipient, + ), ]; case TokenDropInitializer.contractType: case TokenInitializer.contractType: @@ -299,13 +319,19 @@ export class ContractFactory extends ContractWrapper { metadata, ); return [ - await this.getSignerAddress(), + signerAddress, erc20metadata.name, erc20metadata.symbol, contractURI, trustedForwarders, - erc20metadata.primary_sale_recipient, - erc20metadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + erc20metadata.primary_sale_recipient, + ), + overrideFeeRecipient( + signerAddress, + erc20metadata.platform_fee_recipient, + ), erc20metadata.platform_fee_basis_points, ]; case VoteInitializer.contractType: @@ -327,7 +353,7 @@ export class ContractFactory extends ContractWrapper { metadata, ); return [ - await this.getSignerAddress(), + signerAddress, contractURI, trustedForwarders, splitsMetadata.recipients.map((s) => s.address), @@ -337,20 +363,26 @@ export class ContractFactory extends ContractWrapper { const marketplaceMetadata = await MarketplaceInitializer.schema.deploy.parseAsync(metadata); return [ - await this.getSignerAddress(), + signerAddress, contractURI, trustedForwarders, - marketplaceMetadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + marketplaceMetadata.platform_fee_recipient, + ), marketplaceMetadata.platform_fee_basis_points, ]; case MarketplaceV3Initializer.contractType: const marketplaceV3Metadata = await MarketplaceV3Initializer.schema.deploy.parseAsync(metadata); return [ - await this.getSignerAddress(), + signerAddress, contractURI, trustedForwarders, - marketplaceV3Metadata.platform_fee_recipient, + overrideFeeRecipient( + signerAddress, + marketplaceV3Metadata.platform_fee_recipient, + ), marketplaceV3Metadata.platform_fee_basis_points, ]; case PackInitializer.contractType: @@ -358,7 +390,7 @@ export class ContractFactory extends ContractWrapper { metadata, ); return [ - await this.getSignerAddress(), + signerAddress, packsMetadata.name, packsMetadata.symbol, contractURI, diff --git a/packages/sdk/src/evm/core/sdk.ts b/packages/sdk/src/evm/core/sdk.ts index e23910b99ef..72f13aa9a12 100644 --- a/packages/sdk/src/evm/core/sdk.ts +++ b/packages/sdk/src/evm/core/sdk.ts @@ -1566,7 +1566,6 @@ export class ContractDeployer extends RPCConnectionHandler { contractMetadata, )), }; - if (this.hasLocalFactory()) { // old behavior for unit tests, deploy from local factory // parse version into the first number of the version string (or undefined if unparseable) From e9af6fcd830c4e8560e0a3f9f10559e474d5d053 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Wed, 29 Nov 2023 06:18:37 -0500 Subject: [PATCH 2/8] Fix lint --- packages/sdk/src/evm/common/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/evm/common/deploy.ts b/packages/sdk/src/evm/common/deploy.ts index dad7ac7c4fd..ad62d08aea7 100644 --- a/packages/sdk/src/evm/common/deploy.ts +++ b/packages/sdk/src/evm/common/deploy.ts @@ -14,7 +14,7 @@ import { MarketplaceInitializer, MarketplaceV3Initializer, } from "../contracts"; -import { BigNumber, Signer, constants, providers } from "ethers"; +import { BigNumber, Signer, providers } from "ethers"; import { z } from "zod"; import { ThirdwebStorage } from "@thirdweb-dev/storage"; import { SUPPORTED_CHAIN_IDS } from "../constants/chains/SUPPORTED_CHAIN_IDS"; From 53b568d9e7e07e048d46680d7d06d40a8dabc9a9 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Wed, 29 Nov 2023 06:23:57 -0500 Subject: [PATCH 3/8] Revert unwanted change --- packages/sdk/src/evm/core/sdk.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/sdk/src/evm/core/sdk.ts b/packages/sdk/src/evm/core/sdk.ts index 72f13aa9a12..e23910b99ef 100644 --- a/packages/sdk/src/evm/core/sdk.ts +++ b/packages/sdk/src/evm/core/sdk.ts @@ -1566,6 +1566,7 @@ export class ContractDeployer extends RPCConnectionHandler { contractMetadata, )), }; + if (this.hasLocalFactory()) { // old behavior for unit tests, deploy from local factory // parse version into the first number of the version string (or undefined if unparseable) From 629e292f524577468f8bc17177935837d5fe94da Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Wed, 29 Nov 2023 06:30:40 -0500 Subject: [PATCH 4/8] Fix lint --- .../sdk/src/evm/common/override-fee-recipient.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/sdk/src/evm/common/override-fee-recipient.ts b/packages/sdk/src/evm/common/override-fee-recipient.ts index 4997244fa3f..289c463f4b5 100644 --- a/packages/sdk/src/evm/common/override-fee-recipient.ts +++ b/packages/sdk/src/evm/common/override-fee-recipient.ts @@ -3,10 +3,11 @@ import { constants } from "ethers"; /** * In the past we default `platform_fee_recipient` and `primary_sale_recipient` to AddressZero. * However due to a recent change in our smart contract extensions (PrimarySale & PlatformFee), AddressZero is no longer an accepted value for those fields. - * So now we're set the default value to the signer address. - * @reference https://github.com/thirdweb-dev/contracts/pull/530 - * @param signerAddress The address of the contract deployer - * @param fee_recipient The address that will receive the platform fees and/or sale fees + * So now we set the default value to the signer address. + * https://github.com/thirdweb-dev/contracts/pull/530 + * + * @param signerAddress - The address of the contract deployer + * @param fee_recipient - The address that will receive the platform fees and/or sale fees * @returns `signerAddress` if the `fee_recipient` is AddressZero, otherwise returns `fee_recipient` * @internal */ @@ -14,6 +15,8 @@ export function overrideFeeRecipient( signerAddress: string, fee_recipient: string, ): string { - if (fee_recipient === constants.AddressZero) return signerAddress; + if (fee_recipient === constants.AddressZero) { + return signerAddress; + } return fee_recipient; } From a4eac5a8eb750d1c9353a72ad3567b93187c3f1b Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Thu, 14 Dec 2023 17:28:47 -0500 Subject: [PATCH 5/8] Renaming --- packages/sdk/src/evm/common/deploy.ts | 20 ++++++++--------- ...pient.ts => override-recipient-address.ts} | 12 +++++----- .../src/evm/core/classes/internal/factory.ts | 22 +++++++++---------- .../src/evm/schema/contracts/common/index.ts | 6 +++-- 4 files changed, 31 insertions(+), 29 deletions(-) rename packages/sdk/src/evm/common/{override-fee-recipient.ts => override-recipient-address.ts} (62%) diff --git a/packages/sdk/src/evm/common/deploy.ts b/packages/sdk/src/evm/common/deploy.ts index ad62d08aea7..d8e17b4bf7f 100644 --- a/packages/sdk/src/evm/common/deploy.ts +++ b/packages/sdk/src/evm/common/deploy.ts @@ -23,7 +23,7 @@ import type { PrebuiltContractType, DeploySchemaForPrebuiltContractType, } from "../contracts"; -import { overrideFeeRecipient } from "./override-fee-recipient"; +import { overrideRecipientAddress } from "./override-recipient-address"; /** * @@ -75,14 +75,14 @@ export async function getDeployArguments< erc721metadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc721metadata.primary_sale_recipient, ), erc721metadata.fee_recipient, erc721metadata.seller_fee_basis_points, erc721metadata.platform_fee_basis_points, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc721metadata.platform_fee_recipient, ), @@ -96,14 +96,14 @@ export async function getDeployArguments< signatureDropmetadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, signatureDropmetadata.primary_sale_recipient, ), signatureDropmetadata.fee_recipient, signatureDropmetadata.seller_fee_basis_points, signatureDropmetadata.platform_fee_basis_points, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, signatureDropmetadata.platform_fee_recipient, ), @@ -130,14 +130,14 @@ export async function getDeployArguments< erc1155metadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc1155metadata.primary_sale_recipient, ), erc1155metadata.fee_recipient, erc1155metadata.seller_fee_basis_points, erc1155metadata.platform_fee_basis_points, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc1155metadata.platform_fee_recipient, ), @@ -153,11 +153,11 @@ export async function getDeployArguments< erc20metadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc20metadata.primary_sale_recipient, ), - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc20metadata.platform_fee_recipient, ), @@ -196,7 +196,7 @@ export async function getDeployArguments< signerAddress, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, marketplaceMetadata.platform_fee_recipient, ), diff --git a/packages/sdk/src/evm/common/override-fee-recipient.ts b/packages/sdk/src/evm/common/override-recipient-address.ts similarity index 62% rename from packages/sdk/src/evm/common/override-fee-recipient.ts rename to packages/sdk/src/evm/common/override-recipient-address.ts index 289c463f4b5..70ae94ad157 100644 --- a/packages/sdk/src/evm/common/override-fee-recipient.ts +++ b/packages/sdk/src/evm/common/override-recipient-address.ts @@ -7,16 +7,16 @@ import { constants } from "ethers"; * https://github.com/thirdweb-dev/contracts/pull/530 * * @param signerAddress - The address of the contract deployer - * @param fee_recipient - The address that will receive the platform fees and/or sale fees - * @returns `signerAddress` if the `fee_recipient` is AddressZero, otherwise returns `fee_recipient` + * @param recipient - The address that will receive the platform fees and/or sale fees + * @returns `signerAddress` if the `recipient` is AddressZero, otherwise returns `recipient` * @internal */ -export function overrideFeeRecipient( +export function overrideRecipientAddress( signerAddress: string, - fee_recipient: string, + recipient: string, ): string { - if (fee_recipient === constants.AddressZero) { + if (recipient === constants.AddressZero) { return signerAddress; } - return fee_recipient; + return recipient; } diff --git a/packages/sdk/src/evm/core/classes/internal/factory.ts b/packages/sdk/src/evm/core/classes/internal/factory.ts index ab06a371426..6df6d1fb963 100644 --- a/packages/sdk/src/evm/core/classes/internal/factory.ts +++ b/packages/sdk/src/evm/core/classes/internal/factory.ts @@ -42,7 +42,7 @@ import type { DeployEvents } from "../../../types/deploy/deploy-events"; import { NetworkInput } from "../../types"; import { ContractWrapper } from "./contract-wrapper"; import { Transaction } from "../transactions"; -import { overrideFeeRecipient } from "../../../common/override-fee-recipient"; +import { overrideRecipientAddress } from "../../../common/override-recipient-address"; /** * @internal @@ -246,14 +246,14 @@ export class ContractFactory extends ContractWrapper { erc721metadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc721metadata.primary_sale_recipient, ), erc721metadata.fee_recipient, erc721metadata.seller_fee_basis_points, erc721metadata.platform_fee_basis_points, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc721metadata.platform_fee_recipient, ), @@ -267,14 +267,14 @@ export class ContractFactory extends ContractWrapper { signatureDropmetadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, signatureDropmetadata.primary_sale_recipient, ), signatureDropmetadata.fee_recipient, signatureDropmetadata.seller_fee_basis_points, signatureDropmetadata.platform_fee_basis_points, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, signatureDropmetadata.platform_fee_recipient, ), @@ -301,14 +301,14 @@ export class ContractFactory extends ContractWrapper { erc1155metadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc1155metadata.primary_sale_recipient, ), erc1155metadata.fee_recipient, erc1155metadata.seller_fee_basis_points, erc1155metadata.platform_fee_basis_points, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc1155metadata.platform_fee_recipient, ), @@ -324,11 +324,11 @@ export class ContractFactory extends ContractWrapper { erc20metadata.symbol, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc20metadata.primary_sale_recipient, ), - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, erc20metadata.platform_fee_recipient, ), @@ -366,7 +366,7 @@ export class ContractFactory extends ContractWrapper { signerAddress, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, marketplaceMetadata.platform_fee_recipient, ), @@ -379,7 +379,7 @@ export class ContractFactory extends ContractWrapper { signerAddress, contractURI, trustedForwarders, - overrideFeeRecipient( + overrideRecipientAddress( signerAddress, marketplaceV3Metadata.platform_fee_recipient, ), diff --git a/packages/sdk/src/evm/schema/contracts/common/index.ts b/packages/sdk/src/evm/schema/contracts/common/index.ts index 6208d750600..299ebb93590 100644 --- a/packages/sdk/src/evm/schema/contracts/common/index.ts +++ b/packages/sdk/src/evm/schema/contracts/common/index.ts @@ -44,14 +44,16 @@ export const CommonRoyaltySchema = /* @__PURE__ */ (() => * * For example: if this value is 100, then the royalty is 1% of the total sales. * - * @internalremarks used by OpenSea "seller_fee_basis_points" + * @internal + * @remarks used by OpenSea "seller_fee_basis_points" */ seller_fee_basis_points: BasisPointsSchema.default(0), /** * The address of the royalty recipient. All royalties will be sent * to this address. - * @internalremarks used by OpenSea "fee_recipient" + * @internal + * @remarks used by OpenSea "fee_recipient" */ fee_recipient: AddressOrEnsSchema.default(constants.AddressZero), }))(); From 6b6a12ab1e8259603343ebf8a6a9a073f54b7e03 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Thu, 14 Dec 2023 17:29:11 -0500 Subject: [PATCH 6/8] Make primary_sale_recipient optional --- packages/sdk/src/evm/types/deploy/deploy-metadata.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sdk/src/evm/types/deploy/deploy-metadata.ts b/packages/sdk/src/evm/types/deploy/deploy-metadata.ts index eddefca3b7d..ac032649395 100644 --- a/packages/sdk/src/evm/types/deploy/deploy-metadata.ts +++ b/packages/sdk/src/evm/types/deploy/deploy-metadata.ts @@ -35,7 +35,7 @@ export interface NFTContractDeployMetadata { /** * The address that will receive the proceeds from primary sales */ - primary_sale_recipient: AddressOrEns; + primary_sale_recipient?: AddressOrEns; /** * The address that will receive the proceeds from secondary sales (royalties) */ @@ -91,7 +91,7 @@ export interface OpenEditionContractDeployMetadata { /** * The address that will receive the proceeds from primary sales */ - primary_sale_recipient: AddressOrEns; + primary_sale_recipient?: AddressOrEns; /** * The address that will receive the proceeds from secondary sales (royalties) */ @@ -138,7 +138,7 @@ export interface TokenContractDeployMetadata { /** * The address that will receive the proceeds from primary sales */ - primary_sale_recipient: AddressOrEns; + primary_sale_recipient?: AddressOrEns; /** * The address that will receive the proceeds from platform fees */ From 3c114e279e3bde96e1ca59ced2e965951f4fc3a9 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Thu, 14 Dec 2023 17:31:58 -0500 Subject: [PATCH 7/8] Default primary_sale_recipient to AddressZero --- packages/sdk/src/evm/schema/contracts/common/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/evm/schema/contracts/common/index.ts b/packages/sdk/src/evm/schema/contracts/common/index.ts index 299ebb93590..ce6c4df7615 100644 --- a/packages/sdk/src/evm/schema/contracts/common/index.ts +++ b/packages/sdk/src/evm/schema/contracts/common/index.ts @@ -66,7 +66,7 @@ export const CommonPrimarySaleSchema = /* @__PURE__ */ (() => /** * primary sale recipient address */ - primary_sale_recipient: AddressOrEnsSchema, + primary_sale_recipient: AddressOrEnsSchema.default(constants.AddressZero), }))(); /** From 34ff60ac1a2acc9bfebde00dbeb9b91d64ecd5f3 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Thu, 14 Dec 2023 18:04:09 -0500 Subject: [PATCH 8/8] Update test cases --- packages/sdk/test/evm/recipient.test.ts | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 packages/sdk/test/evm/recipient.test.ts diff --git a/packages/sdk/test/evm/recipient.test.ts b/packages/sdk/test/evm/recipient.test.ts new file mode 100644 index 00000000000..bf3c84d5b6a --- /dev/null +++ b/packages/sdk/test/evm/recipient.test.ts @@ -0,0 +1,74 @@ +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { signers, sdk } from "./before-setup"; +import { assert, expect } from "chai"; +import { AddressZero } from "../../src/evm/constants/addresses/AddressZero"; + +describe("Validate address for `platform_fee_recipient` and `primary_sale_recipient`", async () => { + let adminWallet: SignerWithAddress; + + before(async () => { + [adminWallet] = signers; + }); + + beforeEach(async () => { + sdk.updateSignerOrProvider(adminWallet); + }); + + it("platform_fee_recipient should be `signerAddress` if not specified when deploy", async () => { + const marketplaceContractAddress = await sdk.deployer.deployBuiltInContract( + "marketplace-v3", + { + name: "marketplace", + }, + ); + const marketplaceContract = await sdk.getContract( + marketplaceContractAddress, + ); + const signerAddress = await sdk.getSigner()?.getAddress(); + const platformFeeInfo = await marketplaceContract.platformFees.get(); + assert.strictEqual(platformFeeInfo.platform_fee_recipient, signerAddress); + }); + + it("platform_fee_recipient should be `signerAddress` if set to AddressZero when deploy", async () => { + const marketplaceContractAddress = await sdk.deployer.deployBuiltInContract( + "marketplace-v3", + { + name: "marketplace", + platform_fee_recipient: AddressZero, + }, + ); + const marketplaceContract = await sdk.getContract( + marketplaceContractAddress, + ); + const signerAddress = await sdk.getSigner()?.getAddress(); + const platformFeeInfo = await marketplaceContract.platformFees.get(); + assert.strictEqual(platformFeeInfo.platform_fee_recipient, signerAddress); + }); + + it("primary_sale_recipient should be `signerAddress` if not specified when deploy", async () => { + const nftDropAddress = await sdk.deployer.deployBuiltInContract( + "nft-drop", + { + name: "nftDrop", + }, + ); + const nftDropContract = await sdk.getContract(nftDropAddress); + const primarySaleRecipient = await nftDropContract.sales.getRecipient(); + const signerAddress = await sdk.getSigner()?.getAddress(); + assert.strictEqual(primarySaleRecipient, signerAddress); + }); + + it("primary_sale_recipient should be `signerAddress` if set to AddressZero when deploy", async () => { + const nftDropAddress = await sdk.deployer.deployBuiltInContract( + "nft-drop", + { + name: "nftDrop", + primary_sale_recipient: AddressZero, + }, + ); + const nftDropContract = await sdk.getContract(nftDropAddress); + const primarySaleRecipient = await nftDropContract.sales.getRecipient(); + const signerAddress = await sdk.getSigner()?.getAddress(); + assert.strictEqual(primarySaleRecipient, signerAddress); + }); +});