Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] Fix invalid recipient issue when deploy built-in contracts #2020

Merged
merged 9 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { overrideFeeRecipient } from "./override-fee-recipient";

/**
*
Expand Down Expand Up @@ -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 =
Expand All @@ -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 =
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions packages/sdk/src/evm/common/override-fee-recipient.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 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;
}
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 { NetworkInput } from "../../types";
import { ContractWrapper } from "./contract-wrapper";
import { Transaction } from "../transactions";
import { overrideFeeRecipient } from "../../../common/override-fee-recipient";

/**
* @internal
Expand Down Expand Up @@ -233,43 +234,56 @@
if (metadata.trusted_forwarders && metadata.trusted_forwarders.length > 0) {
trustedForwarders = metadata.trusted_forwarders;
}
const signerAddress = await this.getSignerAddress();

Check warning on line 237 in packages/sdk/src/evm/core/classes/internal/factory.ts

View check run for this annotation

Codecov / codecov/patch

packages/sdk/src/evm/core/classes/internal/factory.ts#L237

Added line #L237 was not covered by tests
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,
Expand All @@ -282,30 +296,42 @@
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:
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,
overrideFeeRecipient(
signerAddress,
erc20metadata.primary_sale_recipient,
),
overrideFeeRecipient(
signerAddress,
erc20metadata.platform_fee_recipient,
),
erc20metadata.platform_fee_basis_points,
];
case VoteInitializer.contractType:
Expand All @@ -327,7 +353,7 @@
metadata,
);
return [
await this.getSignerAddress(),
signerAddress,
contractURI,
trustedForwarders,
splitsMetadata.recipients.map((s) => s.address),
Expand All @@ -337,28 +363,34 @@
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:
const packsMetadata = await PackInitializer.schema.deploy.parseAsync(
metadata,
);
return [
await this.getSignerAddress(),
signerAddress,
packsMetadata.name,
packsMetadata.symbol,
contractURI,
Expand Down
Loading