Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kien Ngo committed Nov 29, 2023
1 parent b833250 commit ab9a8cb
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 30 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"
48 changes: 38 additions & 10 deletions packages/sdk/src/evm/common/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
19 changes: 19 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,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;
}
70 changes: 51 additions & 19 deletions packages/sdk/src/evm/core/classes/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 { overrideFeeRecipient } from "../../common/override-fee-recipient";

/**
* @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,
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 @@ 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,
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 @@ 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,
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
1 change: 0 additions & 1 deletion packages/sdk/src/evm/core/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ab9a8cb

Please sign in to comment.