Skip to content

Commit

Permalink
[SDK] Fix invalid recipient issue when deploy built-in contracts (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kien Ngo authored Dec 15, 2023
1 parent b7d4dee commit fed1313
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-ads-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": patch
---

Fix deploy issue "invalid recipient"
46 changes: 37 additions & 9 deletions packages/sdk/src/evm/common/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
PrebuiltContractType,
DeploySchemaForPrebuiltContractType,
} from "../contracts";
import { overrideRecipientAddress } from "./override-recipient-address";

/**
*
Expand Down Expand Up @@ -74,11 +75,17 @@ export async function getDeployArguments<
erc721metadata.symbol,
contractURI,
trustedForwarders,
erc721metadata.primary_sale_recipient,
overrideRecipientAddress(
signerAddress,
erc721metadata.primary_sale_recipient,
),
erc721metadata.fee_recipient,
erc721metadata.seller_fee_basis_points,
erc721metadata.platform_fee_basis_points,
erc721metadata.platform_fee_recipient,
overrideRecipientAddress(
signerAddress,
erc721metadata.platform_fee_recipient,
),
];
case SignatureDropInitializer.contractType:
const signatureDropmetadata =
Expand All @@ -89,11 +96,17 @@ export async function getDeployArguments<
signatureDropmetadata.symbol,
contractURI,
trustedForwarders,
signatureDropmetadata.primary_sale_recipient,
overrideRecipientAddress(
signerAddress,
signatureDropmetadata.primary_sale_recipient,
),
signatureDropmetadata.fee_recipient,
signatureDropmetadata.seller_fee_basis_points,
signatureDropmetadata.platform_fee_basis_points,
signatureDropmetadata.platform_fee_recipient,
overrideRecipientAddress(
signerAddress,
signatureDropmetadata.platform_fee_recipient,
),
];
case MultiwrapInitializer.contractType:
const multiwrapMetadata =
Expand All @@ -117,11 +130,17 @@ export async function getDeployArguments<
erc1155metadata.symbol,
contractURI,
trustedForwarders,
erc1155metadata.primary_sale_recipient,
overrideRecipientAddress(
signerAddress,
erc1155metadata.primary_sale_recipient,
),
erc1155metadata.fee_recipient,
erc1155metadata.seller_fee_basis_points,
erc1155metadata.platform_fee_basis_points,
erc1155metadata.platform_fee_recipient,
overrideRecipientAddress(
signerAddress,
erc1155metadata.platform_fee_recipient,
),
];
case TokenDropInitializer.contractType:
case TokenInitializer.contractType:
Expand All @@ -134,8 +153,14 @@ export async function getDeployArguments<
erc20metadata.symbol,
contractURI,
trustedForwarders,
erc20metadata.primary_sale_recipient,
erc20metadata.platform_fee_recipient,
overrideRecipientAddress(
signerAddress,
erc20metadata.primary_sale_recipient,
),
overrideRecipientAddress(
signerAddress,
erc20metadata.platform_fee_recipient,
),
erc20metadata.platform_fee_basis_points,
];
case VoteInitializer.contractType:
Expand Down Expand Up @@ -171,7 +196,10 @@ export async function getDeployArguments<
signerAddress,
contractURI,
trustedForwarders,
marketplaceMetadata.platform_fee_recipient,
overrideRecipientAddress(
signerAddress,
marketplaceMetadata.platform_fee_recipient,
),
marketplaceMetadata.platform_fee_basis_points,
];
case PackInitializer.contractType:
Expand Down
22 changes: 22 additions & 0 deletions packages/sdk/src/evm/common/override-recipient-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 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 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 overrideRecipientAddress(
signerAddress: string,
recipient: string,
): string {
if (recipient === constants.AddressZero) {
return signerAddress;
}
return recipient;
}
70 changes: 51 additions & 19 deletions packages/sdk/src/evm/core/classes/internal/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { overrideRecipientAddress } from "../../../common/override-recipient-address";

/**
* @internal
Expand Down Expand Up @@ -233,43 +234,56 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
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,
overrideRecipientAddress(
signerAddress,
erc721metadata.primary_sale_recipient,
),
erc721metadata.fee_recipient,
erc721metadata.seller_fee_basis_points,
erc721metadata.platform_fee_basis_points,
erc721metadata.platform_fee_recipient,
overrideRecipientAddress(
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,
overrideRecipientAddress(
signerAddress,
signatureDropmetadata.primary_sale_recipient,
),
signatureDropmetadata.fee_recipient,
signatureDropmetadata.seller_fee_basis_points,
signatureDropmetadata.platform_fee_basis_points,
signatureDropmetadata.platform_fee_recipient,
overrideRecipientAddress(
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,
Expand All @@ -282,30 +296,42 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
const erc1155metadata =
await EditionDropInitializer.schema.deploy.parseAsync(metadata);
return [
await this.getSignerAddress(),
signerAddress,
erc1155metadata.name,
erc1155metadata.symbol,
contractURI,
trustedForwarders,
erc1155metadata.primary_sale_recipient,
overrideRecipientAddress(
signerAddress,
erc1155metadata.primary_sale_recipient,
),
erc1155metadata.fee_recipient,
erc1155metadata.seller_fee_basis_points,
erc1155metadata.platform_fee_basis_points,
erc1155metadata.platform_fee_recipient,
overrideRecipientAddress(
signerAddress,
erc1155metadata.platform_fee_recipient,
),
];
case TokenDropInitializer.contractType:
case TokenInitializer.contractType:
const erc20metadata = await TokenInitializer.schema.deploy.parseAsync(
metadata,
);
return [
await this.getSignerAddress(),
signerAddress,
erc20metadata.name,
erc20metadata.symbol,
contractURI,
trustedForwarders,
erc20metadata.primary_sale_recipient,
erc20metadata.platform_fee_recipient,
overrideRecipientAddress(
signerAddress,
erc20metadata.primary_sale_recipient,
),
overrideRecipientAddress(
signerAddress,
erc20metadata.platform_fee_recipient,
),
erc20metadata.platform_fee_basis_points,
];
case VoteInitializer.contractType:
Expand All @@ -327,7 +353,7 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
metadata,
);
return [
await this.getSignerAddress(),
signerAddress,
contractURI,
trustedForwarders,
splitsMetadata.recipients.map((s) => s.address),
Expand All @@ -337,28 +363,34 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
const marketplaceMetadata =
await MarketplaceInitializer.schema.deploy.parseAsync(metadata);
return [
await this.getSignerAddress(),
signerAddress,
contractURI,
trustedForwarders,
marketplaceMetadata.platform_fee_recipient,
overrideRecipientAddress(
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,
overrideRecipientAddress(
signerAddress,
marketplaceV3Metadata.platform_fee_recipient,
),
marketplaceV3Metadata.platform_fee_basis_points,
];
case PackInitializer.contractType:
const packsMetadata = await PackInitializer.schema.deploy.parseAsync(
metadata,
);
return [
await this.getSignerAddress(),
signerAddress,
packsMetadata.name,
packsMetadata.symbol,
contractURI,
Expand Down
8 changes: 5 additions & 3 deletions packages/sdk/src/evm/schema/contracts/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}))();
Expand All @@ -64,7 +66,7 @@ export const CommonPrimarySaleSchema = /* @__PURE__ */ (() =>
/**
* primary sale recipient address
*/
primary_sale_recipient: AddressOrEnsSchema,
primary_sale_recipient: AddressOrEnsSchema.default(constants.AddressZero),
}))();

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/evm/types/deploy/deploy-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit fed1313

Please sign in to comment.