Skip to content

Commit 55158b4

Browse files
committed
created isSuperchain and isCrosschain flag in favour of case switch statement
1 parent 97e6b99 commit 55158b4

File tree

3 files changed

+118
-129
lines changed

3 files changed

+118
-129
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/cross-chain/data-table.tsx

Lines changed: 82 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,16 @@ export function DataTable({
135135
deployStatusModal.setViewContractLink("");
136136
deployStatusModal.open(steps);
137137

138+
const isCrosschain = !!modulesMetadata?.find(
139+
(m) => m.name === "SuperChainInterop",
140+
);
141+
138142
const crosschainContractAddress = await deployContractfromDeployMetadata({
139143
account: activeAccount,
140144
chain,
141145
client,
142-
deployMetadata: {
143-
...coreMetadata,
144-
deployType: "crosschain" as const,
145-
},
146+
deployMetadata: coreMetadata,
147+
isCrosschain,
146148
initializeData,
147149
salt,
148150
});
@@ -153,93 +155,95 @@ export function DataTable({
153155
client,
154156
});
155157

156-
const owner = await readContract({
157-
contract: coreContract,
158-
method: "function owner() view returns (address)",
159-
params: [],
160-
});
158+
if (isCrosschain) {
159+
const owner = await readContract({
160+
contract: coreContract,
161+
method: "function owner() view returns (address)",
162+
params: [],
163+
});
161164

162-
const moduleInitializeParams = modulesMetadata.reduce(
163-
(acc, mod) => {
164-
const params = getModuleInstallParams(mod);
165-
const paramNames = params
166-
.map((param) => param.name)
167-
.filter((p) => p !== undefined);
168-
const returnVal: Record<string, string> = {};
165+
const moduleInitializeParams = modulesMetadata.reduce(
166+
(acc, mod) => {
167+
const params = getModuleInstallParams(mod);
168+
const paramNames = params
169+
.map((param) => param.name)
170+
.filter((p) => p !== undefined);
171+
const returnVal: Record<string, string> = {};
169172

170-
// set connected wallet address as default "royaltyRecipient"
171-
if (showRoyaltyFieldset(paramNames)) {
172-
returnVal.royaltyRecipient = owner || "";
173-
returnVal.royaltyBps = "0";
174-
returnVal.transferValidator = ZERO_ADDRESS;
175-
}
173+
// set connected wallet address as default "royaltyRecipient"
174+
if (showRoyaltyFieldset(paramNames)) {
175+
returnVal.royaltyRecipient = owner || "";
176+
returnVal.royaltyBps = "0";
177+
returnVal.transferValidator = ZERO_ADDRESS;
178+
}
176179

177-
// set connected wallet address as default "primarySaleRecipient"
178-
else if (showPrimarySaleFiedset(paramNames)) {
179-
returnVal.primarySaleRecipient = owner || "";
180-
}
180+
// set connected wallet address as default "primarySaleRecipient"
181+
else if (showPrimarySaleFiedset(paramNames)) {
182+
returnVal.primarySaleRecipient = owner || "";
183+
}
181184

182-
// set superchain bridge address
183-
else if (showSuperchainBridgeFieldset(paramNames)) {
184-
returnVal.superchainBridge =
185-
"0x4200000000000000000000000000000000000010"; // OP Superchain Bridge
186-
}
185+
// set superchain bridge address
186+
else if (showSuperchainBridgeFieldset(paramNames)) {
187+
returnVal.superchainBridge =
188+
"0x4200000000000000000000000000000000000010"; // OP Superchain Bridge
189+
}
187190

188-
acc[mod.name] = returnVal;
189-
return acc;
190-
},
191-
{} as Record<string, Record<string, string>>,
192-
);
191+
acc[mod.name] = returnVal;
192+
return acc;
193+
},
194+
{} as Record<string, Record<string, string>>,
195+
);
193196

194-
const moduleDeployData = modulesMetadata.map((m) => ({
195-
deployMetadata: m,
196-
initializeParams: moduleInitializeParams[m.name],
197-
}));
197+
const moduleDeployData = modulesMetadata.map((m) => ({
198+
deployMetadata: m,
199+
initializeParams: moduleInitializeParams[m.name],
200+
}));
198201

199-
const contract = getContract({
200-
address: crosschainContractAddress,
201-
chain,
202-
client,
203-
});
202+
const contract = getContract({
203+
address: crosschainContractAddress,
204+
chain,
205+
client,
206+
});
204207

205-
await Promise.all(
206-
moduleDeployData.map(async (m) => {
207-
let moduleData: `0x${string}` | undefined;
208+
await Promise.all(
209+
moduleDeployData.map(async (m) => {
210+
let moduleData: `0x${string}` | undefined;
208211

209-
const moduleInstallParams = m.deployMetadata.abi.find(
210-
(abiType) =>
211-
(abiType as AbiFunction).name === "encodeBytesOnInstall",
212-
) as AbiFunction | undefined;
212+
const moduleInstallParams = m.deployMetadata.abi.find(
213+
(abiType) =>
214+
(abiType as AbiFunction).name === "encodeBytesOnInstall",
215+
) as AbiFunction | undefined;
213216

214-
if (m.initializeParams && moduleInstallParams) {
215-
moduleData = encodeAbiParameters(
216-
(
217-
moduleInstallParams.inputs as { name: string; type: string }[]
218-
).map((p) => ({
219-
name: p.name,
220-
type: p.type,
221-
})),
222-
Object.values(m.initializeParams),
223-
);
224-
}
217+
if (m.initializeParams && moduleInstallParams) {
218+
moduleData = encodeAbiParameters(
219+
(
220+
moduleInstallParams.inputs as { name: string; type: string }[]
221+
).map((p) => ({
222+
name: p.name,
223+
type: p.type,
224+
})),
225+
Object.values(m.initializeParams),
226+
);
227+
}
225228

226-
const installTransaction = installPublishedModule({
227-
contract,
228-
account: activeAccount,
229-
moduleName: m.deployMetadata.name,
230-
publisher: m.deployMetadata.publisher,
231-
version: m.deployMetadata.version,
232-
moduleData,
233-
});
229+
const installTransaction = installPublishedModule({
230+
contract,
231+
account: activeAccount,
232+
moduleName: m.deployMetadata.name,
233+
publisher: m.deployMetadata.publisher,
234+
version: m.deployMetadata.version,
235+
moduleData,
236+
});
234237

235-
const txResult = await sendTransaction({
236-
transaction: installTransaction,
237-
account: activeAccount,
238-
});
238+
const txResult = await sendTransaction({
239+
transaction: installTransaction,
240+
account: activeAccount,
241+
});
239242

240-
return await waitForReceipt(txResult);
241-
}),
242-
);
243+
return await waitForReceipt(txResult);
244+
}),
245+
);
246+
}
243247

244248
deployStatusModal.nextStep();
245249
deployStatusModal.setViewContractLink(

apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
466466
deployMetadata: metadata,
467467
initializeParams,
468468
salt,
469+
isSuperchainInterop,
469470
modules: isSuperchainInterop
470471
? // remove modules for superchain interop in order to deploy deterministically deploy just the core contract
471472
[]

packages/thirdweb/src/extensions/prebuilts/deploy-published.ts

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export type DeployContractfromDeployMetadataOptions = {
123123
initializeParams?: Record<string, unknown>;
124124
initializeData?: `0x${string}`;
125125
implementationConstructorParams?: Record<string, unknown>;
126+
isSuperchainInterop?: boolean;
127+
isCrosschain?: boolean;
126128
modules?: {
127129
deployMetadata: FetchDeployMetadataResult;
128130
initializeParams?: Record<string, unknown>;
@@ -143,6 +145,8 @@ export async function deployContractfromDeployMetadata(
143145
initializeParams,
144146
initializeData,
145147
deployMetadata,
148+
isSuperchainInterop, // TODO: Remove this once the updated Clone Factory has been published
149+
isCrosschain,
146150
implementationConstructorParams,
147151
modules,
148152
salt,
@@ -166,7 +170,7 @@ export async function deployContractfromDeployMetadata(
166170
import("../../contract/deployment/deploy-via-autofactory.js"),
167171
import("../../contract/deployment/utils/bootstrap.js"),
168172
]);
169-
const { cloneFactoryContract: _, implementationContract } =
173+
const { cloneFactoryContract, implementationContract } =
170174
await getOrDeployInfraForPublishedContract({
171175
chain,
172176
client,
@@ -181,15 +185,9 @@ export async function deployContractfromDeployMetadata(
181185
publisher: deployMetadata.publisher,
182186
});
183187

184-
const initializeTransaction = await getInitializeTransaction({
185-
client,
186-
chain,
187-
deployMetadata,
188-
implementationContract,
189-
initializeParams,
190-
account,
191-
modules,
192-
});
188+
console.error("is superchain interop", isSuperchainInterop);
189+
console.error("is crosschain: ", isCrosschain);
190+
console.error("initialize data: ", initializeData);
193191

194192
// TODO: remove this once the modified version of TWCloneFactory
195193
// has been published under the thirdweb wallet
@@ -199,51 +197,37 @@ export async function deployContractfromDeployMetadata(
199197
chain,
200198
});
201199

202-
return await deployViaAutoFactory({
203-
client,
204-
chain,
205-
account,
206-
cloneFactoryContract: modifiedCloneFactoryContract,
207-
initializeTransaction,
208-
salt,
209-
});
210-
}
211-
case "crosschain": {
212-
const { getOrDeployInfraForPublishedContract } = await import(
213-
"../../contract/deployment/utils/bootstrap.js"
214-
);
215-
const { cloneFactoryContract: _, implementationContract } =
216-
await getOrDeployInfraForPublishedContract({
200+
if (isCrosschain) {
201+
return await deployViaAutoFactoryWithImplementationParams({
202+
client,
217203
chain,
204+
account,
205+
cloneFactoryContract: modifiedCloneFactoryContract,
206+
implementationAddress: implementationContract.address,
207+
initializeData,
208+
salt,
209+
});
210+
} else {
211+
const initializeTransaction = await getInitializeTransaction({
218212
client,
213+
chain,
214+
deployMetadata,
215+
implementationContract,
216+
initializeParams,
219217
account,
220-
contractId: deployMetadata.name,
221-
constructorParams:
222-
implementationConstructorParams ||
223-
(await getAllDefaultConstructorParamsForImplementation({
224-
chain,
225-
client,
226-
})),
227-
publisher: deployMetadata.publisher,
218+
modules,
228219
});
229-
230-
// TODO: remove this once the modified version of TWCloneFactory
231-
// has been published under the thirdweb wallet
232-
const modifiedCloneFactoryContract = getContract({
233-
client,
234-
address: "0xB83db4b940e4796aA1f53DBFC824B9B1865835D5", // only deployed on OP and zora testnets
235-
chain,
236-
});
237-
238-
return await deployViaAutoFactoryWithImplementationParams({
239-
client,
240-
chain,
241-
account,
242-
cloneFactoryContract: modifiedCloneFactoryContract,
243-
implementationAddress: implementationContract.address,
244-
initializeData,
245-
salt,
246-
});
220+
return await deployViaAutoFactory({
221+
client,
222+
chain,
223+
account,
224+
cloneFactoryContract: isSuperchainInterop // TODO: remove this once the updated clone factory is publsihed
225+
? modifiedCloneFactoryContract
226+
: cloneFactoryContract,
227+
initializeTransaction,
228+
salt,
229+
});
230+
}
247231
}
248232
case "customFactory": {
249233
if (!deployMetadata?.factoryDeploymentData?.customFactoryInput) {

0 commit comments

Comments
 (0)