Skip to content

Commit

Permalink
update generateTsAbis logic to create two seprate deployements file
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 committed Dec 19, 2023
1 parent afe5f3f commit 3c3df36
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/hardhat/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ artifacts
artifacts-zk
cache-zk

deployments
deployments/localhost
26 changes: 23 additions & 3 deletions packages/hardhat/deploy/99_generateTsAbis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,33 @@ const generateTsAbis: DeployFunction = async function () {
const TARGET_DIR = "../nextjs/contracts/";
const allContractsData = getContractDataFromDeployments();

if (!fs.existsSync(TARGET_DIR)) {
fs.mkdirSync(TARGET_DIR);
}

if ("31337" in allContractsData) {
const deployedLocalhostContracts = allContractsData["31337"];
const deployedLocalhostContractsFileContent = `31337: ${JSON.stringify(deployedLocalhostContracts, null, 2)}`;
fs.writeFileSync(
`${TARGET_DIR}deployedLocalhostContracts.ts`,
prettier.format(
`${generatedContractComment} import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; \n\n
const deployedLocalhostContracts = {${deployedLocalhostContractsFileContent}} as const; \n\n export default deployedLocalhostContracts satisfies GenericContractsDeclaration`,
{
parser: "typescript",
},
),
);
delete allContractsData["31337"];
}

/* const deployedLocalhostContractts = allContractsData["31337"];
console.log("All contracts data", allContractsData); */

const fileContent = Object.entries(allContractsData).reduce((content, [chainId, chainConfig]) => {
return `${content}${parseInt(chainId).toFixed(0)}:${JSON.stringify(chainConfig, null, 2)},`;
}, "");

if (!fs.existsSync(TARGET_DIR)) {
fs.mkdirSync(TARGET_DIR);
}
fs.writeFileSync(
`${TARGET_DIR}deployedContracts.ts`,
prettier.format(
Expand Down
9 changes: 9 additions & 0 deletions packages/nextjs/contracts/deployedLocalhostContracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* This file is autogenerated by Scaffold-ETH.
* You should not edit it manually or your changes might be overwritten.
*/
import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";

const deployedLocalhostContracts = {} as const;

export default deployedLocalhostContracts satisfies GenericContractsDeclaration;
4 changes: 3 additions & 1 deletion packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "viem";
import { UseContractEventConfig, UseContractReadConfig, UseContractWriteConfig } from "wagmi";
import deployedContractsData from "~~/contracts/deployedContracts";
import deployedLocalhostContractsData from "~~/contracts/deployedLocalhostContracts";
import externalContractsData from "~~/contracts/externalContracts";
import scaffoldConfig from "~~/scaffold.config";

Expand All @@ -34,7 +35,8 @@ const deepMergeContracts = <D extends Record<PropertyKey, any>, S extends Record
}
return result as MergeDeepRecord<D, S, { arrayMergeMode: "replace" }>;
};
const contractsData = deepMergeContracts(deployedContractsData, externalContractsData);
const allDeployedContracts = deepMergeContracts(deployedContractsData, deployedLocalhostContractsData);
const contractsData = deepMergeContracts(allDeployedContracts, externalContractsData);

export type InheritedFunctions = { readonly [key: string]: string };

Expand Down

0 comments on commit 3c3df36

Please sign in to comment.