Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.
Merged
28 changes: 28 additions & 0 deletions docs/sdk.contractdeployer.deployviafactory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@thirdweb-dev/sdk](./sdk.md) &gt; [ContractDeployer](./sdk.contractdeployer.md) &gt; [deployViaFactory](./sdk.contractdeployer.deployviafactory.md)

## ContractDeployer.deployViaFactory() method

Deploy a proxy contract of a given implementation via the given factory

<b>Signature:</b>

```typescript
deployViaFactory(factoryAddress: string, implementationAddress: string, implementationAbi: ContractInterface, initializerFunction: string, initializerArgs: any[]): Promise<string>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| factoryAddress | string | |
| implementationAddress | string | |
| implementationAbi | ContractInterface | |
| initializerFunction | string | |
| initializerArgs | any\[\] | |

<b>Returns:</b>

Promise&lt;string&gt;

1 change: 1 addition & 0 deletions docs/sdk.contractdeployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export declare class ContractDeployer extends RPCConnectionHandler
| [deploySplit(metadata)](./sdk.contractdeployer.deploysplit.md) | | Deploys a new Split contract |
| [deployToken(metadata)](./sdk.contractdeployer.deploytoken.md) | | Deploys a new Token contract |
| [deployTokenDrop(metadata)](./sdk.contractdeployer.deploytokendrop.md) | | Deploys a new Token Drop contract |
| [deployViaFactory(factoryAddress, implementationAddress, implementationAbi, initializerFunction, initializerArgs)](./sdk.contractdeployer.deployviafactory.md) | | Deploy a proxy contract of a given implementation via the given factory |
| [deployVote(metadata)](./sdk.contractdeployer.deployvote.md) | | Deploys a new Vote contract |
| [updateSignerOrProvider(network)](./sdk.contractdeployer.updatesignerorprovider.md) | | |

119 changes: 112 additions & 7 deletions etc/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ export enum ChainId {
Rinkeby = 4
}

// Warning: (ae-internal-missing-underscore) The name "ChainIdToAddressSchema" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const ChainIdToAddressSchema: z.ZodRecord<z.ZodString, z.ZodString>;

// Warning: (ae-internal-missing-underscore) The name "ChainOrRpc" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
Expand Down Expand Up @@ -1170,6 +1175,7 @@ export class ContractDeployer extends RPCConnectionHandler {
deploySplit(metadata: SplitContractDeployMetadata): Promise<string>;
deployToken(metadata: TokenContractDeployMetadata): Promise<string>;
deployTokenDrop(metadata: TokenContractDeployMetadata): Promise<string>;
deployViaFactory(factoryAddress: string, implementationAddress: string, implementationAbi: ContractInterface, initializerFunction: string, initializerArgs: any[]): Promise<string>;
deployVote(metadata: VoteContractDeployMetadata): Promise<string>;
// Warning: (ae-forgotten-export) The symbol "ContractRegistry" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -1560,7 +1566,9 @@ export const CustomContractOutput: z.ZodObject<z.extendShape<z.extendShape<{
image: z.ZodOptional<z.ZodUnion<[z.ZodTypeAny, z.ZodString]>>;
external_link: z.ZodOptional<z.ZodString>;
}, {
image: z.ZodOptional<z.ZodString>;
image: z.ZodOptional<z.ZodString>; /**
* @internal
*/
}>, {
merkle: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>>;
seller_fee_basis_points: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
Expand Down Expand Up @@ -1642,7 +1650,9 @@ export const CustomContractSchema: {
image: z.ZodOptional<z.ZodUnion<[z.ZodTypeAny, z.ZodString]>>;
external_link: z.ZodOptional<z.ZodString>;
}, {
image: z.ZodOptional<z.ZodString>;
image: z.ZodOptional<z.ZodString>; /**
* @internal
*/
}>, {
merkle: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>>;
seller_fee_basis_points: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
Expand Down Expand Up @@ -2800,6 +2810,21 @@ export function extractConstructorParamsFromAbi(abi: z.input<typeof AbiSchema>):
// @internal (undocumented)
export function extractEventsFromAbi(abi: z.input<typeof AbiSchema>, metadata?: Record<string, any>): AbiEvent[];

// Warning: (ae-internal-missing-underscore) The name "extractFunctionParamsFromAbi" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export function extractFunctionParamsFromAbi(abi: z.input<typeof AbiSchema>, functionName: string): {
[x: string]: any;
components?: {
[x: string]: any;
type: string;
name: string;
}[] | undefined;
stateMutability?: string | undefined;
type: string;
name: string;
}[];

// Warning: (ae-internal-missing-underscore) The name "extractFunctions" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
Expand All @@ -2826,6 +2851,21 @@ export const ExtraPublishMetadataSchema: z.ZodObject<{
license: z.ZodOptional<z.ZodString>;
changelog: z.ZodOptional<z.ZodString>;
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
logo: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodTypeAny, z.ZodString]>>>;
isDeployableViaFactory: z.ZodOptional<z.ZodBoolean>;
factoryDeploymentData: z.ZodOptional<z.ZodObject<{
implementationAddresses: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
implementationInitializerFunction: z.ZodOptional<z.ZodDefault<z.ZodString>>;
factoryAddresses: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>>;
}, "strip", z.ZodTypeAny, {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
}, {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
}>>;
}, "strip", z.ZodAny, {
[x: string]: any;
description?: string | undefined;
Expand All @@ -2834,6 +2874,13 @@ export const ExtraPublishMetadataSchema: z.ZodObject<{
license?: string | undefined;
changelog?: string | undefined;
tags?: string[] | undefined;
logo?: any;
isDeployableViaFactory?: boolean | undefined;
factoryDeploymentData?: {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
} | undefined;
version: string;
}, {
[x: string]: any;
Expand All @@ -2843,9 +2890,33 @@ export const ExtraPublishMetadataSchema: z.ZodObject<{
license?: string | undefined;
changelog?: string | undefined;
tags?: string[] | undefined;
logo?: any;
isDeployableViaFactory?: boolean | undefined;
factoryDeploymentData?: {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
} | undefined;
version: string;
}>;

// Warning: (ae-internal-missing-underscore) The name "FactoryDeploymentSchema" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const FactoryDeploymentSchema: z.ZodObject<{
implementationAddresses: z.ZodRecord<z.ZodString, z.ZodString>;
implementationInitializerFunction: z.ZodDefault<z.ZodString>;
factoryAddresses: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
}, "strip", z.ZodTypeAny, {
implementationAddresses: Record<string, string>;
implementationInitializerFunction: string;
factoryAddresses: Record<string, string>;
}, {
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
implementationAddresses: Record<string, string>;
}>;

// Warning: (ae-internal-missing-underscore) The name "fetchContractMetadata" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
Expand Down Expand Up @@ -2902,9 +2973,14 @@ export class FetchError extends Error {
innerError?: Error;
}

// Warning: (ae-internal-missing-underscore) The name "fetchExtendedReleaseMetadata" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export function fetchExtendedReleaseMetadata(publishMetadataUri: string, storage: IStorage): Promise<FullPublishMetadata>;

// Warning: (ae-internal-missing-underscore) The name "fetchPreDeployMetadata" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
// @internal
export function fetchPreDeployMetadata(publishMetadataUri: string, storage: IStorage): Promise<PreDeployMetadataFetched>;

// Warning: (ae-internal-missing-underscore) The name "fetchRawPredeployMetadata" should be prefixed with an underscore because the declaration is marked as @internal
Expand Down Expand Up @@ -2994,6 +3070,21 @@ export const FullPublishMetadataSchema: z.ZodObject<z.extendShape<z.extendShape<
license: z.ZodOptional<z.ZodString>;
changelog: z.ZodOptional<z.ZodString>;
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
logo: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodTypeAny, z.ZodString]>>>;
isDeployableViaFactory: z.ZodOptional<z.ZodBoolean>;
factoryDeploymentData: z.ZodOptional<z.ZodObject<{
implementationAddresses: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
implementationInitializerFunction: z.ZodOptional<z.ZodDefault<z.ZodString>>;
factoryAddresses: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>>;
}, "strip", z.ZodTypeAny, {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
}, {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
}>>;
}>, {
publisher: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
}>, "strip", z.ZodAny, {
Expand All @@ -3006,6 +3097,13 @@ export const FullPublishMetadataSchema: z.ZodObject<z.extendShape<z.extendShape<
license?: string | undefined;
changelog?: string | undefined;
tags?: string[] | undefined;
logo?: any;
isDeployableViaFactory?: boolean | undefined;
factoryDeploymentData?: {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
} | undefined;
name: string;
version: string;
metadataUri: string;
Expand All @@ -3020,6 +3118,13 @@ export const FullPublishMetadataSchema: z.ZodObject<z.extendShape<z.extendShape<
license?: string | undefined;
changelog?: string | undefined;
tags?: string[] | undefined;
logo?: any;
isDeployableViaFactory?: boolean | undefined;
factoryDeploymentData?: {
implementationAddresses?: Record<string, string> | undefined;
implementationInitializerFunction?: string | undefined;
factoryAddresses?: Record<string, string> | undefined;
} | undefined;
name: string;
version: string;
metadataUri: string;
Expand Down Expand Up @@ -7158,10 +7263,10 @@ export class WrongListingTypeError extends Error {

// Warnings were encountered during analysis:
//
// dist/src/schema/contracts/custom.d.ts:1279:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1280:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1287:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1288:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1361:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1362:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1369:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1370:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal

// (No @packageDocumentation comment for this package)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "2.3.36",
"version": "2.3.37-0",
"description": "The main thirdweb SDK.",
"repository": {
"type": "git",
Expand Down
45 changes: 45 additions & 0 deletions src/common/feature-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
AbiTypeSchema,
ContractInfoSchema,
ContractSource,
FullPublishMetadata,
FullPublishMetadataSchema,
PreDeployMetadata,
PreDeployMetadataFetched,
PreDeployMetadataFetchedSchema,
Expand Down Expand Up @@ -117,6 +119,25 @@ export function extractConstructorParamsFromAbi(
return [];
}

/**
*
* @param abi
* @param functionName
* @returns
* @internal
*/
export function extractFunctionParamsFromAbi(
abi: z.input<typeof AbiSchema>,
functionName: string,
) {
for (const input of abi) {
if (input.type === "function" && input.name === functionName) {
return input.inputs ?? [];
}
}
return [];
}

/**
* @internal
* @param abi
Expand Down Expand Up @@ -228,6 +249,15 @@ export async function resolveContractUriFromAddress(
`Contract at ${address} does not exist on chain '${chain.name}' (chainId: ${chain.chainId})`,
);
}
// EIP-1167 clone proxy - https://eips.ethereum.org/EIPS/eip-1167
if (bytecode.startsWith("0x363d3d373d3d3d363d")) {
const implementationAddress = bytecode.slice(22, 62);
return resolveContractUriFromAddress(
`0x${implementationAddress}`,
provider,
);
}
// TODO support other types of proxies like erc1967
return extractIPFSHashFromBytecode(bytecode);
}

Expand Down Expand Up @@ -391,6 +421,7 @@ export async function fetchRawPredeployMetadata(
}

/**
* Fetch the metadata coming from CLI, this is before deploying or releasing the contract.
* @internal
* @param publishMetadataUri
* @param storage
Expand All @@ -409,6 +440,20 @@ export async function fetchPreDeployMetadata(
});
}

/**
* Fetch and parse the full metadata AFTER creating a release, with all the extra information (version, readme, etc)
* @internal
* @param publishMetadataUri
* @param storage
*/
export async function fetchExtendedReleaseMetadata(
publishMetadataUri: string,
storage: IStorage,
): Promise<FullPublishMetadata> {
const meta = await storage.getRaw(publishMetadataUri);
return FullPublishMetadataSchema.parse(JSON.parse(meta));
}

/**
* Processes ALL supported features and sets whether the passed in abi supports each individual feature
* @internal
Expand Down
Loading