Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/gentle-countries-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": patch
---

Perf improvement for getting deployment info
83 changes: 40 additions & 43 deletions packages/sdk/src/evm/common/any-evm-utils/getDeploymentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ export async function getDeploymentInfo(
secretKey?: string,
): Promise<DeploymentPreset[]> {
caches.deploymentPresets = {};

const create2FactoryAddress = create2Factory
? create2Factory
: await getCreate2FactoryAddress(provider);

const [create2FactoryAddress, { compilerMetadata, extendedMetadata }] =
await Promise.all([
create2Factory ? create2Factory : getCreate2FactoryAddress(provider),
fetchAndCacheDeployMetadata(metadataUri, storage),
]);
const customParams: ConstructorParamMap = {};
const finalDeploymentInfo: DeploymentPreset[] = [];
const { compilerMetadata, extendedMetadata } =
await fetchAndCacheDeployMetadata(metadataUri, storage);
const defaultExtensions = extendedMetadata?.defaultExtensions;

if (extendedMetadata?.routerType === "plugin" && defaultExtensions) {
Expand All @@ -65,26 +63,25 @@ export async function getDeploymentInfo(

const pluginMetadata = (
await Promise.all(
publishedExtensions.map(async (c) => {
return fetchAndCacheDeployMetadata(c.metadataUri, storage);
}),
publishedExtensions.map((c) =>
fetchAndCacheDeployMetadata(c.metadataUri, storage),
),
)
).map((fetchedMetadata) => fetchedMetadata.compilerMetadata);

// get deployment info for all plugins
const pluginDeploymentInfo = await Promise.all(
pluginMetadata.map(async (metadata) => {
const info = await computeDeploymentInfo(
pluginMetadata.map((metadata) =>
computeDeploymentInfo(
"plugin",
provider,
storage,
create2FactoryAddress,
{ metadata: metadata },
clientId,
secretKey,
);
return info;
}),
),
),
);

// create constructor param input for PluginMap
Expand Down Expand Up @@ -142,18 +139,17 @@ export async function getDeploymentInfo(

// get deployment info for all extensions
const extensionDeploymentInfo = await Promise.all(
extensionMetadata.map(async (metadata) => {
const info = await computeDeploymentInfo(
extensionMetadata.map((metadata) =>
computeDeploymentInfo(
"extension",
provider,
storage,
create2FactoryAddress,
{ metadata: metadata },
clientId,
secretKey,
);
return info;
}),
),
),
);

// create constructor param input for BaseRouter
Expand All @@ -179,29 +175,30 @@ export async function getDeploymentInfo(
finalDeploymentInfo.push(...extensionDeploymentInfo);
}

const implementationDeployInfo = await computeDeploymentInfo(
"implementation",
provider,
storage,
create2FactoryAddress,
{
metadata: compilerMetadata,
constructorParams: customParams,
},
clientId,
secretKey,
);

// get clone factory
const factoryInfo = await computeDeploymentInfo(
"infra",
provider,
storage,
create2FactoryAddress,
{ contractName: "TWCloneFactory" },
clientId,
secretKey,
);
const [implementationDeployInfo, factoryInfo] = await Promise.all([
computeDeploymentInfo(
"implementation",
provider,
storage,
create2FactoryAddress,
{
metadata: compilerMetadata,
constructorParams: customParams,
},
clientId,
secretKey,
),
// get clone factory
computeDeploymentInfo(
"infra",
provider,
storage,
create2FactoryAddress,
{ contractName: "TWCloneFactory" },
clientId,
secretKey,
),
]);

finalDeploymentInfo.push(factoryInfo);
finalDeploymentInfo.push(...Object.values(caches.deploymentPresets));
Expand Down