Skip to content

Commit 2936839

Browse files
committed
enable for direct deploys
1 parent 47dc5ed commit 2936839

File tree

2 files changed

+166
-97
lines changed

2 files changed

+166
-97
lines changed

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

Lines changed: 134 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ import { useForm } from "react-hook-form";
4646
import {
4747
ZERO_ADDRESS,
4848
defineChain,
49+
eth_getCode,
4950
eth_getTransactionCount,
5051
getContract,
5152
getRpcClient,
5253
prepareContractCall,
54+
prepareTransaction,
5355
readContract,
5456
sendAndConfirmTransaction,
5557
sendTransaction,
@@ -77,7 +79,14 @@ type CrossChain = {
7779
status: "DEPLOYED" | "NOT_DEPLOYED";
7880
};
7981

80-
type ChainId = "84532" | "11155420" | "919" | "111557560" | "999999999";
82+
type ChainId =
83+
| "84532"
84+
| "11155420"
85+
| "919"
86+
| "111557560"
87+
| "999999999"
88+
| "11155111"
89+
| "421614";
8190

8291
const formSchema = z.object({
8392
amounts: z.object({
@@ -100,13 +109,15 @@ export function DataTable({
100109
modulesMetadata,
101110
initializeData,
102111
inputSalt,
112+
initCode,
103113
}: {
104114
data: CrossChain[];
105115
coreMetadata: FetchDeployMetadataResult;
106116
coreContract: ThirdwebContract;
107117
modulesMetadata?: FetchDeployMetadataResult[];
108118
initializeData?: `0x${string}`;
109119
inputSalt?: `0x${string}`;
120+
initCode?: `0x${string}`;
110121
}) {
111122
const activeAccount = useActiveAccount();
112123
const switchChain = useSwitchActiveWalletChain();
@@ -285,121 +296,148 @@ export function DataTable({
285296
(m) => m.name === "SuperChainInterop",
286297
);
287298

288-
const crosschainContractAddress = await deployContractfromDeployMetadata({
289-
account: activeAccount,
290-
chain,
291-
client,
292-
deployMetadata: coreMetadata,
293-
isCrosschain: true,
294-
initializeData,
295-
salt,
296-
});
297-
298-
verifyContract({
299-
address: crosschainContractAddress,
300-
chain,
301-
client,
302-
});
303-
304-
if (isCrosschain && modulesMetadata) {
305-
const owner = await readContract({
306-
contract: coreContract,
307-
method: "function owner() view returns (address)",
308-
params: [],
299+
let crosschainContractAddress: string | undefined;
300+
if (initCode) {
301+
const tx = prepareTransaction({
302+
client,
303+
chain,
304+
to: "0x4e59b44847b379578588920cA78FbF26c0B4956C",
305+
data: initCode,
309306
});
310307

311-
const moduleInitializeParams = modulesMetadata.reduce(
312-
(acc, mod) => {
313-
const params = getModuleInstallParams(mod);
314-
const paramNames = params
315-
.map((param) => param.name)
316-
.filter((p) => p !== undefined);
317-
const returnVal: Record<string, string> = {};
318-
319-
// set connected wallet address as default "royaltyRecipient"
320-
if (showRoyaltyFieldset(paramNames)) {
321-
returnVal.royaltyRecipient = owner || "";
322-
returnVal.royaltyBps = "0";
323-
returnVal.transferValidator = ZERO_ADDRESS;
324-
}
325-
326-
// set connected wallet address as default "primarySaleRecipient"
327-
else if (showPrimarySaleFieldset(paramNames)) {
328-
returnVal.primarySaleRecipient = owner || "";
329-
}
330-
331-
// set superchain bridge address
332-
else if (showSuperchainBridgeFieldset(paramNames)) {
333-
returnVal.superchainBridge =
334-
"0x4200000000000000000000000000000000000028"; // OP Superchain Bridge
335-
}
308+
await sendAndConfirmTransaction({
309+
transaction: tx,
310+
account: activeAccount,
311+
});
336312

337-
acc[mod.name] = returnVal;
338-
return acc;
313+
const code = await eth_getCode(
314+
getRpcClient({
315+
client,
316+
chain,
317+
}),
318+
{
319+
address: coreContract.address,
339320
},
340-
{} as Record<string, Record<string, string>>,
341321
);
342322

343-
const moduleDeployData = modulesMetadata.map((m) => ({
344-
deployMetadata: m,
345-
initializeParams: moduleInitializeParams[m.name],
346-
}));
347-
348-
const contract = getContract({
349-
address: crosschainContractAddress,
323+
if (code && code.length > 2) {
324+
crosschainContractAddress = coreContract.address;
325+
}
326+
} else {
327+
crosschainContractAddress = await deployContractfromDeployMetadata({
328+
account: activeAccount,
350329
chain,
351330
client,
331+
deployMetadata: coreMetadata,
332+
isCrosschain: true,
333+
initializeData,
334+
salt,
352335
});
353336

354-
const rpcRequest = getRpcClient({
355-
client,
337+
verifyContract({
338+
address: crosschainContractAddress,
356339
chain,
340+
client,
357341
});
358-
const currentNonce = await eth_getTransactionCount(rpcRequest, {
359-
address: activeAccount.address,
360-
});
342+
if (isCrosschain && modulesMetadata) {
343+
const owner = await readContract({
344+
contract: coreContract,
345+
method: "function owner() view returns (address)",
346+
params: [],
347+
});
361348

362-
for (const [i, m] of moduleDeployData.entries()) {
363-
let moduleData: `0x${string}` | undefined;
364-
365-
const moduleInstallParams = m.deployMetadata.abi.find(
366-
(abiType) =>
367-
(abiType as AbiFunction).name === "encodeBytesOnInstall",
368-
) as AbiFunction | undefined;
369-
370-
if (m.initializeParams && moduleInstallParams) {
371-
moduleData = encodeAbiParameters(
372-
(
373-
moduleInstallParams.inputs as { name: string; type: string }[]
374-
).map((p) => ({
375-
name: p.name,
376-
type: p.type,
377-
})),
378-
Object.values(m.initializeParams),
379-
);
380-
}
349+
const moduleInitializeParams = modulesMetadata.reduce(
350+
(acc, mod) => {
351+
const params = getModuleInstallParams(mod);
352+
const paramNames = params
353+
.map((param) => param.name)
354+
.filter((p) => p !== undefined);
355+
const returnVal: Record<string, string> = {};
356+
357+
// set connected wallet address as default "royaltyRecipient"
358+
if (showRoyaltyFieldset(paramNames)) {
359+
returnVal.royaltyRecipient = owner || "";
360+
returnVal.royaltyBps = "0";
361+
returnVal.transferValidator = ZERO_ADDRESS;
362+
}
363+
364+
// set connected wallet address as default "primarySaleRecipient"
365+
else if (showPrimarySaleFieldset(paramNames)) {
366+
returnVal.primarySaleRecipient = owner || "";
367+
}
368+
369+
// set superchain bridge address
370+
else if (showSuperchainBridgeFieldset(paramNames)) {
371+
returnVal.superchainBridge =
372+
"0x4200000000000000000000000000000000000028"; // OP Superchain Bridge
373+
}
374+
375+
acc[mod.name] = returnVal;
376+
return acc;
377+
},
378+
{} as Record<string, Record<string, string>>,
379+
);
381380

382-
const installTransaction = installPublishedModule({
383-
contract,
384-
account: activeAccount,
385-
moduleName: m.deployMetadata.name,
386-
publisher: m.deployMetadata.publisher,
387-
version: m.deployMetadata.version,
388-
moduleData,
389-
nonce: currentNonce + i,
381+
const moduleDeployData = modulesMetadata.map((m) => ({
382+
deployMetadata: m,
383+
initializeParams: moduleInitializeParams[m.name],
384+
}));
385+
386+
const contract = getContract({
387+
address: crosschainContractAddress,
388+
chain,
389+
client,
390390
});
391391

392-
const txResult = await sendTransaction({
393-
transaction: installTransaction,
394-
account: activeAccount,
392+
const rpcRequest = getRpcClient({
393+
client,
394+
chain,
395+
});
396+
const currentNonce = await eth_getTransactionCount(rpcRequest, {
397+
address: activeAccount.address,
395398
});
396399

397-
await waitForReceipt(txResult);
398-
// can't handle parallel transactions, so wait a bit
399-
await new Promise((resolve) => setTimeout(resolve, 1000));
400+
for (const [i, m] of moduleDeployData.entries()) {
401+
let moduleData: `0x${string}` | undefined;
402+
403+
const moduleInstallParams = m.deployMetadata.abi.find(
404+
(abiType) =>
405+
(abiType as AbiFunction).name === "encodeBytesOnInstall",
406+
) as AbiFunction | undefined;
407+
408+
if (m.initializeParams && moduleInstallParams) {
409+
moduleData = encodeAbiParameters(
410+
(
411+
moduleInstallParams.inputs as { name: string; type: string }[]
412+
).map((p) => ({
413+
name: p.name,
414+
type: p.type,
415+
})),
416+
Object.values(m.initializeParams),
417+
);
418+
}
419+
420+
const installTransaction = installPublishedModule({
421+
contract,
422+
account: activeAccount,
423+
moduleName: m.deployMetadata.name,
424+
publisher: m.deployMetadata.publisher,
425+
version: m.deployMetadata.version,
426+
moduleData,
427+
nonce: currentNonce + i,
428+
});
429+
430+
const txResult = await sendTransaction({
431+
transaction: installTransaction,
432+
account: activeAccount,
433+
});
434+
435+
await waitForReceipt(txResult);
436+
// can't handle parallel transactions, so wait a bit
437+
await new Promise((resolve) => setTimeout(resolve, 1000));
438+
}
400439
}
401440
}
402-
403441
deployStatusModal.nextStep();
404442
deployStatusModal.setViewContractLink(
405443
`/${chain.id}/${crosschainContractAddress}`,

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { fetchPublishedContractsFromDeploy } from "components/contract-components/fetchPublishedContractsFromDeploy";
22
import { notFound } from "next/navigation";
3-
import { getContractEvents, prepareEvent } from "thirdweb";
3+
import {
4+
eth_getTransactionByHash,
5+
getContractEvents,
6+
prepareEvent,
7+
} from "thirdweb";
48
import { defineChain, getChainMetadata, localhost } from "thirdweb/chains";
59
import {
610
type FetchDeployMetadataResult,
@@ -52,12 +56,38 @@ export default async function Page(props: {
5256
},
5357
);
5458

59+
let initCode: `0x${string}` = "0x";
60+
try {
61+
const res = await fetch(
62+
`https://contract.thirdweb-dev.com/creation/${contract.chain.id}/${contract.address}`,
63+
);
64+
const creationData = await res.json();
65+
66+
if (creationData.status === "1" && creationData.result[0]?.txHash) {
67+
const creationTx = await eth_getTransactionByHash(
68+
getRpcClient({
69+
client: contract.client,
70+
chain: defineChain(84532),
71+
}),
72+
{ hash: creationData.result[0]?.txHash },
73+
);
74+
75+
if (creationTx.to === "0x4e59b44847b379578588920cA78FbF26c0B4956C") {
76+
initCode = creationTx.input;
77+
}
78+
}
79+
} catch (e) {
80+
console.debug(e);
81+
}
82+
5583
const topOPStackTestnetChainIds = [
5684
84532, // Base
5785
11155420, // OP testnet
5886
919, // Mode Network
5987
111557560, // Cyber
6088
999999999, // Zora
89+
11155111, // sepolia
90+
421614,
6191
];
6292

6393
const chainsDeployedOn = await Promise.all(
@@ -143,6 +173,7 @@ export default async function Page(props: {
143173
inputSalt={event?.args.inputSalt}
144174
data={chainsDeployedOn}
145175
coreContract={contract}
176+
initCode={initCode}
146177
/>
147178
);
148179
}

0 commit comments

Comments
 (0)