Skip to content

Commit d6b2c25

Browse files
committed
Register zksync contract on multichain registry after deployment (#3717)
<!-- start pr-codex --> ## PR-Codex overview The focus of this PR is to enhance the deployment process of contracts by adding a gas override option and improving the registration process on the multichain registry for ZkSync contracts. ### Detailed summary - Added `gasOverride` option for contract deployment - Improved ZkSync contract registration process - Removed unnecessary contract registration function - Updated contract deployment handling for ZkSync - Refactored contract deployment logic and metadata handling > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 742207c commit d6b2c25

File tree

4 files changed

+52
-79
lines changed

4 files changed

+52
-79
lines changed

apps/dashboard/src/components/contract-components/hooks.ts

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
extractEventsFromAbi,
3131
extractFunctionParamsFromAbi,
3232
extractFunctionsFromAbi,
33+
fetchAndCacheDeployMetadata,
3334
fetchContractMetadata,
3435
fetchPreDeployMetadata,
3536
fetchRawPredeployMetadata,
@@ -638,6 +639,12 @@ export function useCustomContractDeployMutation(
638639
// open the modal with the appropriate steps
639640
deployContext.open(steps);
640641

642+
const isZkSync =
643+
chainId === Zksync.chainId ||
644+
chainId === ZksyncSepoliaTestnet.chainId ||
645+
chainId === ZkcandySepoliaTestnet.chainId ||
646+
chainId === ZksyncEraGoerliTestnetDeprecated.chainId;
647+
641648
let contractAddress: string;
642649
try {
643650
if (hasContractURI) {
@@ -692,14 +699,15 @@ export function useCustomContractDeployMutation(
692699
}
693700

694701
// Handle ZkSync deployments separately
695-
const isZkSync =
696-
chainId === Zksync.chainId ||
697-
chainId === ZksyncSepoliaTestnet.chainId ||
698-
chainId === ZkcandySepoliaTestnet.chainId ||
699-
chainId === ZksyncEraGoerliTestnetDeprecated.chainId;
700702

701703
// deploy contract
702704
if (isZkSync) {
705+
const publishUri = ipfsHash.startsWith("ipfs://")
706+
? ipfsHash
707+
: `ipfs://${ipfsHash}`;
708+
709+
let uriToRegister = "";
710+
703711
if (
704712
fullPublishMetadata?.data?.compilers?.zksolc ||
705713
rawPredeployMetadata?.data?.compilers?.zksolc
@@ -712,9 +720,7 @@ export function useCustomContractDeployMutation(
712720
: data.saltForCreate2;
713721

714722
contractAddress = await zkDeployContractFromUri(
715-
ipfsHash.startsWith("ipfs://")
716-
? ipfsHash
717-
: `ipfs://${ipfsHash}`,
723+
publishUri,
718724
Object.values(data.deployParams),
719725
signer,
720726
StorageSingleton,
@@ -729,9 +735,7 @@ export function useCustomContractDeployMutation(
729735
);
730736
} else {
731737
contractAddress = await zkDeployContractFromUri(
732-
ipfsHash.startsWith("ipfs://")
733-
? ipfsHash
734-
: `ipfs://${ipfsHash}`,
738+
publishUri,
735739
Object.values(data.deployParams),
736740
signer,
737741
StorageSingleton,
@@ -743,15 +747,44 @@ export function useCustomContractDeployMutation(
743747
},
744748
);
745749
}
750+
751+
const { compilerMetadata } = await fetchAndCacheDeployMetadata(
752+
publishUri,
753+
StorageSingleton,
754+
{
755+
compilerType: "zksolc",
756+
},
757+
);
758+
uriToRegister = compilerMetadata.fetchedMetadataUri;
746759
} else {
747760
contractAddress = await zkDeployContractFromUri(
748-
ipfsHash.startsWith("ipfs://") ? ipfsHash : `ipfs://${ipfsHash}`,
761+
publishUri,
749762
Object.values(data.deployParams),
750763
signer,
751764
StorageSingleton,
752765
chainId as number,
753766
);
767+
768+
const { compilerMetadata } = await fetchAndCacheDeployMetadata(
769+
publishUri,
770+
StorageSingleton,
771+
{
772+
compilerType: "zksolc",
773+
},
774+
);
775+
uriToRegister = compilerMetadata.fetchedMetadataUri;
754776
}
777+
778+
// register deployed zksync contract on multichain registry
779+
await addContractToMultiChainRegistry(
780+
{
781+
address: contractAddress,
782+
chainId,
783+
metadataURI: uriToRegister,
784+
},
785+
account,
786+
300000n,
787+
);
755788
} else {
756789
if (data.deployDeterministic) {
757790
const salt = data.signerAsSalt
@@ -805,7 +838,7 @@ export function useCustomContractDeployMutation(
805838

806839
try {
807840
// let user decide if they want this or not
808-
if (data.addToDashboard) {
841+
if (data.addToDashboard && !isZkSync) {
809842
invariant(chainId, "chainId is not provided");
810843
await addContractToMultiChainRegistry(
811844
{

apps/dashboard/src/components/contract-components/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const registry = getContract({
7373
export async function addContractToMultiChainRegistry(
7474
contractData: AddContractInput,
7575
account: Account,
76+
gasOverride?: bigint,
7677
) {
7778
const transaction = prepareContractCall({
7879
contract: registry,
@@ -86,7 +87,10 @@ export async function addContractToMultiChainRegistry(
8687
});
8788

8889
await sendAndConfirmTransaction({
89-
transaction,
90+
transaction: {
91+
...transaction,
92+
gas: gasOverride || transaction.gas,
93+
},
9094
account,
9195
gasless: {
9296
experimentalChainlessSupport: true,

legacy_packages/sdk/src/evm/zksync/zkDeployContractDeterministic.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { isZkContractDeployed } from "./isZkContractDeployed";
55
import {
66
Contract,
77
Signer,
8-
Wallet,
98
ContractFactory as ZkContractFactory,
109
} from "zksync-ethers";
1110
import { DeployOptions } from "../types/deploy/deploy-options";
@@ -18,7 +17,6 @@ import { PrecomputedDeploymentTransaction } from "./types/deploy-data";
1817
import { zkVerify } from "./zksync-verification";
1918
import { blockExplorerApiMap } from "./constants/addresses";
2019
import { ThirdwebStorage } from "@thirdweb-dev/storage";
21-
import { ThirdwebSDK } from "../core/sdk";
2220

2321
/**
2422
* Deploy a contract at a deterministic address, using Create2 method
@@ -110,16 +108,9 @@ export async function zkDeployContractDeterministic(
110108
}
111109
}
112110

113-
// register on multichain registry, and verify -- no await
111+
// verify -- no await
114112
if (metadataUri && storage) {
115113
const chainId = await signer.getChainId();
116-
try {
117-
registerContractOnMultiChainRegistry(
118-
transaction.predictedAddress,
119-
chainId,
120-
metadataUri,
121-
);
122-
} catch (error) {}
123114

124115
zkVerify(
125116
transaction.predictedAddress,
@@ -134,41 +125,3 @@ export async function zkDeployContractDeterministic(
134125
}
135126
}
136127
}
137-
138-
export async function registerContractOnMultiChainRegistry(
139-
address: string,
140-
chainId: number,
141-
metadataURI: string,
142-
) {
143-
try {
144-
// random wallet is fine here, we're doing gasless calls
145-
const wallet = Wallet.createRandom();
146-
const sdk = ThirdwebSDK.fromPrivateKey(wallet.privateKey, "polygon", {
147-
gasless: {
148-
openzeppelin: {
149-
relayerUrl:
150-
"https://api.defender.openzeppelin.com/autotasks/dad61716-3624-46c9-874f-0e73f15f04d5/runs/webhook/7d6a1834-dd33-4b7b-8af4-b6b4719a0b97/FdHMqyF3p6MGHw6K2nkLsv",
151-
relayerForwarderAddress: "0x409d530a6961297ece29121dbee2c917c3398659",
152-
},
153-
experimentalChainlessSupport: true,
154-
},
155-
});
156-
const existingMeta = await sdk.multiChainRegistry.getContractMetadataURI(
157-
chainId,
158-
address,
159-
);
160-
if (existingMeta && existingMeta !== "") {
161-
return true;
162-
}
163-
// add to multichain registry with metadata uri unlocks the contract on SDK/dashboard for everyone
164-
await sdk.multiChainRegistry.addContract({
165-
address,
166-
chainId,
167-
metadataURI,
168-
});
169-
return true;
170-
} catch (e) {
171-
console.debug("Error registering contract on multi chain registry", e);
172-
return false;
173-
}
174-
}

legacy_packages/sdk/src/evm/zksync/zksync-deploy-utils.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { DeploymentTransaction } from "../types/any-evm/deploy-data";
1919
import { zkDeployCreate2Factory } from "./zkDeployCreate2Factory";
2020
import { getZkDeploymentInfo } from "./getZkDeploymentInfo";
2121
import {
22-
registerContractOnMultiChainRegistry,
2322
zkDeployContractDeterministic,
2423
} from "./zkDeployContractDeterministic";
2524
import invariant from "tiny-invariant";
@@ -206,13 +205,6 @@ export async function zkDeployContractFromUri(
206205

207206
await proxy.deployed();
208207

209-
// register on multichain registry
210-
await registerContractOnMultiChainRegistry(
211-
proxy.address,
212-
chainId,
213-
compilerMetadata.fetchedMetadataUri,
214-
);
215-
216208
deployedAddress = proxy.address;
217209
} else {
218210
throw new Error("Invalid deploy type");
@@ -292,15 +284,6 @@ export async function zkDeployContractFromUri(
292284
const contract = await factory.deploy(...paramValues);
293285
deployedAddress = contract.address;
294286
}
295-
296-
if (deployedAddress) {
297-
// register on multichain registry
298-
await registerContractOnMultiChainRegistry(
299-
deployedAddress,
300-
chainId,
301-
compilerMetadata.fetchedMetadataUri,
302-
);
303-
}
304287
}
305288

306289
// fire-and-forget verification, don't await

0 commit comments

Comments
 (0)