@diamondslab/diamonds 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +618 -0
- package/diamonds/README.md +3 -0
- package/dist/core/CallbackManager.d.ts +13 -0
- package/dist/core/CallbackManager.d.ts.map +1 -0
- package/dist/core/CallbackManager.js +95 -0
- package/dist/core/CallbackManager.js.map +1 -0
- package/dist/core/DeploymentManager.d.ts +10 -0
- package/dist/core/DeploymentManager.d.ts.map +1 -0
- package/dist/core/DeploymentManager.js +50 -0
- package/dist/core/DeploymentManager.js.map +1 -0
- package/dist/core/Diamond.d.ts +58 -0
- package/dist/core/Diamond.d.ts.map +1 -0
- package/dist/core/Diamond.js +146 -0
- package/dist/core/Diamond.js.map +1 -0
- package/dist/core/DiamondDeployer.d.ts +10 -0
- package/dist/core/DiamondDeployer.d.ts.map +1 -0
- package/dist/core/DiamondDeployer.js +33 -0
- package/dist/core/DiamondDeployer.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/repositories/DBDeploymentRepository.d.ts +1 -0
- package/dist/repositories/DBDeploymentRepository.d.ts.map +1 -0
- package/dist/repositories/DBDeploymentRepository.js +20 -0
- package/dist/repositories/DBDeploymentRepository.js.map +1 -0
- package/dist/repositories/DeploymentRepository.d.ts +8 -0
- package/dist/repositories/DeploymentRepository.d.ts.map +1 -0
- package/dist/repositories/DeploymentRepository.js +7 -0
- package/dist/repositories/DeploymentRepository.js.map +1 -0
- package/dist/repositories/FileDeploymentRepository.d.ts +18 -0
- package/dist/repositories/FileDeploymentRepository.d.ts.map +1 -0
- package/dist/repositories/FileDeploymentRepository.js +58 -0
- package/dist/repositories/FileDeploymentRepository.js.map +1 -0
- package/dist/repositories/databaseHandler.d.ts +1 -0
- package/dist/repositories/databaseHandler.d.ts.map +1 -0
- package/dist/repositories/databaseHandler.js +13 -0
- package/dist/repositories/databaseHandler.js.map +1 -0
- package/dist/repositories/index.d.ts +4 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +20 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/jsonFileHandler.d.ts +81 -0
- package/dist/repositories/jsonFileHandler.d.ts.map +1 -0
- package/dist/repositories/jsonFileHandler.js +223 -0
- package/dist/repositories/jsonFileHandler.js.map +1 -0
- package/dist/repositories/prismaDBHandler.d.ts +1 -0
- package/dist/repositories/prismaDBHandler.d.ts.map +1 -0
- package/dist/repositories/prismaDBHandler.js +11 -0
- package/dist/repositories/prismaDBHandler.js.map +1 -0
- package/dist/schemas/DeploymentSchema.d.ts +309 -0
- package/dist/schemas/DeploymentSchema.d.ts.map +1 -0
- package/dist/schemas/DeploymentSchema.js +56 -0
- package/dist/schemas/DeploymentSchema.js.map +1 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +18 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/strategies/BaseDeploymentStrategy.d.ts +41 -0
- package/dist/strategies/BaseDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/BaseDeploymentStrategy.js +545 -0
- package/dist/strategies/BaseDeploymentStrategy.js.map +1 -0
- package/dist/strategies/DeploymentStrategy.d.ts +19 -0
- package/dist/strategies/DeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/DeploymentStrategy.js +3 -0
- package/dist/strategies/DeploymentStrategy.js.map +1 -0
- package/dist/strategies/LocalDeploymentStrategy.d.ts +4 -0
- package/dist/strategies/LocalDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/LocalDeploymentStrategy.js +8 -0
- package/dist/strategies/LocalDeploymentStrategy.js.map +1 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.d.ts +62 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.js +757 -0
- package/dist/strategies/OZDefenderDeploymentStrategy.js.map +1 -0
- package/dist/strategies/RPCDeploymentStrategy.d.ts +139 -0
- package/dist/strategies/RPCDeploymentStrategy.d.ts.map +1 -0
- package/dist/strategies/RPCDeploymentStrategy.js +710 -0
- package/dist/strategies/RPCDeploymentStrategy.js.map +1 -0
- package/dist/strategies/index.d.ts +6 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +12 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/types/config.d.ts +26 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +3 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/defender.d.ts +22 -0
- package/dist/types/defender.d.ts.map +1 -0
- package/dist/types/defender.js +3 -0
- package/dist/types/defender.js.map +1 -0
- package/dist/types/deployments.d.ts +71 -0
- package/dist/types/deployments.d.ts.map +1 -0
- package/dist/types/deployments.js +20 -0
- package/dist/types/deployments.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/rpc.d.ts +35 -0
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/rpc.js +3 -0
- package/dist/types/rpc.js.map +1 -0
- package/dist/utils/common.d.ts +20 -0
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +45 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/configurationResolver.d.ts +30 -0
- package/dist/utils/configurationResolver.d.ts.map +1 -0
- package/dist/utils/configurationResolver.js +151 -0
- package/dist/utils/configurationResolver.js.map +1 -0
- package/dist/utils/contractMapping.d.ts +29 -0
- package/dist/utils/contractMapping.d.ts.map +1 -0
- package/dist/utils/contractMapping.js +224 -0
- package/dist/utils/contractMapping.js.map +1 -0
- package/dist/utils/defenderClients.d.ts +5 -0
- package/dist/utils/defenderClients.d.ts.map +1 -0
- package/dist/utils/defenderClients.js +21 -0
- package/dist/utils/defenderClients.js.map +1 -0
- package/dist/utils/defenderStore.d.ts +14 -0
- package/dist/utils/defenderStore.d.ts.map +1 -0
- package/dist/utils/defenderStore.js +92 -0
- package/dist/utils/defenderStore.js.map +1 -0
- package/dist/utils/diamondAbiGenerator.d.ts +113 -0
- package/dist/utils/diamondAbiGenerator.d.ts.map +1 -0
- package/dist/utils/diamondAbiGenerator.js +415 -0
- package/dist/utils/diamondAbiGenerator.js.map +1 -0
- package/dist/utils/diffDeployedFacets.d.ts +26 -0
- package/dist/utils/diffDeployedFacets.d.ts.map +1 -0
- package/dist/utils/diffDeployedFacets.js +106 -0
- package/dist/utils/diffDeployedFacets.js.map +1 -0
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/loupe.d.ts +44 -0
- package/dist/utils/loupe.d.ts.map +1 -0
- package/dist/utils/loupe.js +128 -0
- package/dist/utils/loupe.js.map +1 -0
- package/dist/utils/rpcStore.d.ts +36 -0
- package/dist/utils/rpcStore.d.ts.map +1 -0
- package/dist/utils/rpcStore.js +166 -0
- package/dist/utils/rpcStore.js.map +1 -0
- package/dist/utils/signer.d.ts +36 -0
- package/dist/utils/signer.d.ts.map +1 -0
- package/dist/utils/signer.js +91 -0
- package/dist/utils/signer.js.map +1 -0
- package/dist/utils/txlogging.d.ts +13 -0
- package/dist/utils/txlogging.d.ts.map +1 -0
- package/dist/utils/txlogging.js +87 -0
- package/dist/utils/txlogging.js.map +1 -0
- package/dist/utils/workspaceSetup.d.ts +32 -0
- package/dist/utils/workspaceSetup.d.ts.map +1 -0
- package/dist/utils/workspaceSetup.js +311 -0
- package/dist/utils/workspaceSetup.js.map +1 -0
- package/docs/DIAMOND_ABI_CONFIGURATION_SUMMARY.md +40 -0
- package/docs/DIAMOND_ABI_GENERATION.md +220 -0
- package/docs/DIAMOND_ABI_GENERATOR_EXAMPLES.md +1204 -0
- package/docs/DIAMOND_ABI_GENERATOR_IMPLEMENTATION.md +947 -0
- package/docs/DIAMOND_ABI_GENERATOR_QUICK_REFERENCE.md +336 -0
- package/docs/README-DEFENDER.md +394 -0
- package/docs/README_DIAMOND_ABI_GENERATOR.md +303 -0
- package/docs/ROADMAP.md +250 -0
- package/docs/assets/image.png +0 -0
- package/docs/defender-integration.md +451 -0
- package/docs/diamond_module-BaseStrategy_design-v2.uxf +247 -0
- package/docs/diamond_module-BaseStrategy_design.uxf +272 -0
- package/docs/monitoring-troubleshooting.md +556 -0
- package/docs/testing-guide.md +713 -0
- package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/callbacks/ERC20ProxyFacet.ts +31 -0
- package/examples/Diamond_Config_and_Deployment_examples/diamonds/ProxyDiamond/proxydiamond.config.json +27 -0
- package/examples/Local_Hardhat_Deployer_Script_example/LocalDiamondDeployer.ts +180 -0
- package/examples/OZ_Defender_Deployer_Script_example/OZDiamondDeployer.ts +107 -0
- package/examples/OZ_Defender_Deployer_Script_example/run-oz-deploy.ts +17 -0
- package/examples/Test_examples/ProxyDiamondDeployment.test.ts +202 -0
- package/examples/defender-deployment/.env.example +35 -0
- package/examples/defender-deployment/README.md +415 -0
- package/examples/defender-deployment/contracts/ExampleDiamond.sol +41 -0
- package/examples/defender-deployment/contracts/ExampleFacet1.sol +84 -0
- package/examples/defender-deployment/contracts/ExampleFacet2.sol +104 -0
- package/examples/defender-deployment/contracts/UpgradeFacet.sol +92 -0
- package/examples/defender-deployment/deploy-script.ts +170 -0
- package/examples/defender-deployment/diamond-config.json +36 -0
- package/examples/defender-deployment/upgrade-script.ts +237 -0
- package/examples/hardhat-diamonds-config.example.ts +41 -0
- package/package.json +228 -0
- package/src/core/CallbackManager.ts +70 -0
- package/src/core/DeploymentManager.ts +64 -0
- package/src/core/Diamond.ts +197 -0
- package/src/core/DiamondDeployer.ts +36 -0
- package/src/core/index.ts +4 -0
- package/src/index.ts +5 -0
- package/src/repositories/DBDeploymentRepository.ts +22 -0
- package/src/repositories/DeploymentRepository.ts +12 -0
- package/src/repositories/FileDeploymentRepository.ts +67 -0
- package/src/repositories/databaseHandler.ts +14 -0
- package/src/repositories/index.ts +4 -0
- package/src/repositories/jsonFileHandler.ts +252 -0
- package/src/repositories/prismaDBHandler.ts +10 -0
- package/src/schemas/DeploymentSchema.ts +71 -0
- package/src/schemas/index.ts +1 -0
- package/src/strategies/BaseDeploymentStrategy.ts +649 -0
- package/src/strategies/DeploymentStrategy.ts +25 -0
- package/src/strategies/LocalDeploymentStrategy.ts +5 -0
- package/src/strategies/OZDefenderDeploymentStrategy.ts +849 -0
- package/src/strategies/RPCDeploymentStrategy.ts +881 -0
- package/src/strategies/index.ts +5 -0
- package/src/types/config.ts +34 -0
- package/src/types/defender.ts +24 -0
- package/src/types/deployments.ts +102 -0
- package/src/types/index.ts +4 -0
- package/src/types/rpc.ts +37 -0
- package/src/utils/common.ts +54 -0
- package/src/utils/configurationResolver.ts +141 -0
- package/src/utils/contractMapping.ts +220 -0
- package/src/utils/defenderClients.ts +22 -0
- package/src/utils/defenderStore.ts +62 -0
- package/src/utils/diamondAbiGenerator.ts +523 -0
- package/src/utils/diffDeployedFacets.ts +131 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/loupe.ts +159 -0
- package/src/utils/rpcStore.ts +152 -0
- package/src/utils/signer.ts +93 -0
- package/src/utils/txlogging.ts +97 -0
- package/src/utils/workspaceSetup.ts +315 -0
- package/test/README.md +136 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DeploymentRepository } from './DeploymentRepository';
|
|
2
|
+
import { DeployedDiamondData, DeployConfig } from '../schemas';
|
|
3
|
+
import { readDeployFile, writeDeployInfo, readDeployConfig } from './jsonFileHandler';
|
|
4
|
+
import { DiamondConfig } from '../types';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
|
|
8
|
+
export class FileDeploymentRepository implements DeploymentRepository {
|
|
9
|
+
private deploymentDataPath: string;
|
|
10
|
+
private deployedDiamondDataFilePath: string;
|
|
11
|
+
private configFilePath: string;
|
|
12
|
+
private writeDeployedDiamondData: boolean;
|
|
13
|
+
private deploymentId: string;
|
|
14
|
+
|
|
15
|
+
constructor(config: DiamondConfig) {
|
|
16
|
+
this.deploymentDataPath = config.deploymentsPath! || 'diamonds';
|
|
17
|
+
this.writeDeployedDiamondData = config.writeDeployedDiamondData ?? true;
|
|
18
|
+
this.deploymentId = `${config.diamondName.toLowerCase()}-${config.networkName!.toLowerCase()}-${config.chainId!.toString()}`;
|
|
19
|
+
|
|
20
|
+
if (config.deployedDiamondDataFilePath) {
|
|
21
|
+
this.deployedDiamondDataFilePath = config.deployedDiamondDataFilePath;
|
|
22
|
+
} else {
|
|
23
|
+
this.deployedDiamondDataFilePath = join(
|
|
24
|
+
this.deploymentDataPath,
|
|
25
|
+
config.diamondName,
|
|
26
|
+
`deployments/${this.deploymentId}.json`
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
if (config.configFilePath) {
|
|
30
|
+
this.configFilePath = config.configFilePath;
|
|
31
|
+
} else {
|
|
32
|
+
this.configFilePath = join(
|
|
33
|
+
this.deploymentDataPath,
|
|
34
|
+
config.diamondName,
|
|
35
|
+
`${config.diamondName.toLowerCase()}.config.json`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public setWriteDeployedDiamondData(write: boolean): void {
|
|
41
|
+
this.writeDeployedDiamondData = write;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getWriteDeployedDiamondData(): boolean {
|
|
45
|
+
return this.writeDeployedDiamondData;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
loadDeployedDiamondData(): DeployedDiamondData {
|
|
49
|
+
return readDeployFile(this.deployedDiamondDataFilePath, this.writeDeployedDiamondData);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
saveDeployedDiamondData(info: DeployedDiamondData): void {
|
|
53
|
+
if (this.writeDeployedDiamondData) {
|
|
54
|
+
writeDeployInfo(this.deployedDiamondDataFilePath, info);
|
|
55
|
+
} else {
|
|
56
|
+
console.log(chalk.cyanBright("Skipping write of diamond deployment data. Set writeDeployedDiamondData to true to enable."));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
loadDeployConfig(): DeployConfig {
|
|
61
|
+
return readDeployConfig(this.configFilePath);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public getDeploymentId(): string {
|
|
65
|
+
return this.deploymentId;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// import { DeployedDiamondData, DeployConfig } from "../schemas";
|
|
2
|
+
|
|
3
|
+
// // This would internally use your chosen DB driver (e.g. pg, Prisma, TypeORM)
|
|
4
|
+
// export async function readDeployedDiamondData(network: string, diamond: string): Promise<DeployedDiamondData> {
|
|
5
|
+
// // SQL or ORM call here
|
|
6
|
+
// }
|
|
7
|
+
|
|
8
|
+
// export async function saveDeploymentInfo(network: string, diamond: string, info: DeployedDiamondData): Promise<void> {
|
|
9
|
+
// // SQL or ORM upsert
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
// export async function getDeployConfigData(projectId: string): Promise<DeployConfig> {
|
|
13
|
+
// // SQL or ORM fetch
|
|
14
|
+
// }
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRUD and validation helpers for JSON files
|
|
3
|
+
*
|
|
4
|
+
* These should all be synchronous and handle issues like empty files or non-existent files
|
|
5
|
+
* gracefully in a way that allows for control by the caller, e.g. gives the caller the
|
|
6
|
+
* ability to create an empty file on failure.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
ensureFileSync,
|
|
11
|
+
existsSync,
|
|
12
|
+
pathExistsSync,
|
|
13
|
+
readJsonSync,
|
|
14
|
+
removeSync,
|
|
15
|
+
writeJsonSync
|
|
16
|
+
} from "fs-extra";
|
|
17
|
+
import { join, resolve } from "path";
|
|
18
|
+
import {
|
|
19
|
+
DeployConfig,
|
|
20
|
+
DeployConfigSchema,
|
|
21
|
+
DeployedDiamondData,
|
|
22
|
+
DeployedDiamondDataSchema
|
|
23
|
+
} from "../schemas/DeploymentSchema";
|
|
24
|
+
|
|
25
|
+
export function readDeployFilePathDiamondNetwork(
|
|
26
|
+
networkName: string,
|
|
27
|
+
diamondName: string,
|
|
28
|
+
deploymentId: string,
|
|
29
|
+
deploymentsPath: string,
|
|
30
|
+
createNew: boolean = false
|
|
31
|
+
): DeployedDiamondData {
|
|
32
|
+
const filePath = join(deploymentsPath, diamondName, `${deploymentId}.json`);
|
|
33
|
+
return readDeployFile(filePath, createNew);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reads and validates a JSON file as DeployedDiamondData
|
|
38
|
+
* @param path - The path to the deployment file.
|
|
39
|
+
* @param createIfMissing - If true, creates a new deployment file with default values if
|
|
40
|
+
* the file does not exist. Otherwise this will throw an error if the file does not exist.
|
|
41
|
+
* @returns The parsed and validated deployment object.
|
|
42
|
+
*/
|
|
43
|
+
export function readDeployFile(path: string, createNew: boolean = true)
|
|
44
|
+
: DeployedDiamondData {
|
|
45
|
+
let raw: unknown;
|
|
46
|
+
if (!pathExistsSync(path) && createNew) {
|
|
47
|
+
createNewDeployFile(path);
|
|
48
|
+
raw = readJsonSync(path);
|
|
49
|
+
|
|
50
|
+
const parsed = DeployedDiamondDataSchema.safeParse(raw);
|
|
51
|
+
if (!parsed.success) {
|
|
52
|
+
throw new Error(`Invalid deployment format: ${JSON.stringify(parsed.error.format(), null, 2)}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return parsed.data;
|
|
56
|
+
} else if (pathExistsSync(path)) {
|
|
57
|
+
raw = readJsonSync(path);
|
|
58
|
+
const parsed = DeployedDiamondDataSchema.safeParse(raw);
|
|
59
|
+
if (!parsed.success) {
|
|
60
|
+
throw new Error(`Invalid deployment format: ${JSON.stringify(parsed.error.format(), null, 2)}`);
|
|
61
|
+
}
|
|
62
|
+
return parsed.data;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// This is a mock deployment object with empty values
|
|
66
|
+
return defaultDeployment();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Resolves the absolute path of a file relative to the project root.
|
|
71
|
+
* @param relativePath - The relative path to resolve.
|
|
72
|
+
* @returns The absolute path.
|
|
73
|
+
*/
|
|
74
|
+
const resolvePath = (relativePath: string): string => {
|
|
75
|
+
return resolve(process.cwd(), relativePath);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Default deployment object with empty values
|
|
80
|
+
* This is used to create a new deployment file if it does not exist or for a mock deployment.
|
|
81
|
+
* @type {DeployedDiamondData}
|
|
82
|
+
*/
|
|
83
|
+
export function defaultDeployment(): DeployedDiamondData {
|
|
84
|
+
return {
|
|
85
|
+
DiamondAddress: "",
|
|
86
|
+
DeployerAddress: "",
|
|
87
|
+
DeployedFacets: {}, // Empty object for facets
|
|
88
|
+
ExternalLibraries: {}, // Empty object for external libraries
|
|
89
|
+
protocolVersion: 0, // Default protocol version
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates a new deployment file with default empty values
|
|
94
|
+
* @param path - The path to the deployment file.
|
|
95
|
+
*/
|
|
96
|
+
export function createNewDeployFile(path: string) {
|
|
97
|
+
// Ensure the directory exists before writing
|
|
98
|
+
ensureFileSync(path);
|
|
99
|
+
// Validate the default deployment object before writing
|
|
100
|
+
const validated = DeployedDiamondDataSchema.parse(defaultDeployment());
|
|
101
|
+
writeJsonSync(path, validated, { spaces: 2 });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Writes JSON to file
|
|
106
|
+
*/
|
|
107
|
+
export function writeDeployInfo(path: string, data: DeployedDiamondData) {
|
|
108
|
+
const validated = DeployedDiamondDataSchema.parse(data);
|
|
109
|
+
writeJsonSync(path, validated, { spaces: 2 });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Update deployment JSON file
|
|
114
|
+
*/
|
|
115
|
+
export function updateDeployInfo(path: string, updater: (data: DeployedDiamondData) => void) {
|
|
116
|
+
const data = readDeployFile(path);
|
|
117
|
+
updater(data);
|
|
118
|
+
writeDeployInfo(path, data);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Deletes the deployment file
|
|
123
|
+
*/
|
|
124
|
+
export function deleteDeployInfo(path: string) {
|
|
125
|
+
if (pathExistsSync(path)) {
|
|
126
|
+
removeSync(path);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Validates the Deployment File without loading it.
|
|
132
|
+
* @param path
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
export function validateDeployFile(path: string): boolean {
|
|
136
|
+
try {
|
|
137
|
+
if (!pathExistsSync(path)) {
|
|
138
|
+
console.log(`Deployment file not found: ${path}`);
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const raw = readJsonSync(path);
|
|
142
|
+
DeployedDiamondDataSchema.parse(raw);
|
|
143
|
+
return true;
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function loadFacetsConfig(
|
|
150
|
+
deploymentsPath: string,
|
|
151
|
+
diamondName: string
|
|
152
|
+
): DeployConfig {
|
|
153
|
+
const file = join(deploymentsPath, diamondName, `${diamondName}.config.json`);
|
|
154
|
+
const valid = validateDeployConfig(file);
|
|
155
|
+
|
|
156
|
+
const facets = readDeployConfig(file);
|
|
157
|
+
return facets;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Loads and validates the facets config <diamondName>.config.json file.
|
|
162
|
+
* @param filePath - The path to the facets file.
|
|
163
|
+
* @returns The parsed and validated facets object.
|
|
164
|
+
*/
|
|
165
|
+
export const readDeployConfig = (filePath: string): DeployConfig => {
|
|
166
|
+
try {
|
|
167
|
+
const fullPath = resolvePath(filePath);
|
|
168
|
+
|
|
169
|
+
// Read the JSON file
|
|
170
|
+
const raw = readJsonSync(fullPath);
|
|
171
|
+
|
|
172
|
+
// Validate and parse the JSON data
|
|
173
|
+
return DeployConfigSchema.parse(raw);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
console.error('Failed to load facets:', e);
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Saves the Diamond Config object to a file.
|
|
182
|
+
* @param filePath - The path to the facets file.
|
|
183
|
+
* @param data - The facets object to save.
|
|
184
|
+
*/
|
|
185
|
+
export const saveDeployConfig = (filePath: string, data: DeployConfig): void => {
|
|
186
|
+
const fullPath = resolvePath(filePath);
|
|
187
|
+
ensureFileSync(fullPath);
|
|
188
|
+
writeJsonSync(fullPath, data, { spaces: 2 });
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Updates a specific facet in the facets file.
|
|
193
|
+
* @param filePath - The path to the facets file.
|
|
194
|
+
* @param facetKey - The key of the facet to update.
|
|
195
|
+
* @param update - The partial update to apply to the facet.
|
|
196
|
+
* @returns The updated facets object.
|
|
197
|
+
*/
|
|
198
|
+
export const updateFacetConfig = (
|
|
199
|
+
filePath: string,
|
|
200
|
+
facetKey: string,
|
|
201
|
+
update: Partial<DeployConfig["facets"][string]>
|
|
202
|
+
): DeployConfig => {
|
|
203
|
+
const deployConfig = readDeployConfig(filePath);
|
|
204
|
+
deployConfig.facets[facetKey] = {
|
|
205
|
+
...(deployConfig.facets[facetKey] || {}),
|
|
206
|
+
...update,
|
|
207
|
+
};
|
|
208
|
+
saveDeployConfig(filePath, deployConfig);
|
|
209
|
+
return deployConfig;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Deletes a specific facet from the facets file.
|
|
214
|
+
* @param filePath - The path to the facets file.
|
|
215
|
+
* @param facetKey - The key of the facet to delete.
|
|
216
|
+
* @returns The updated facets object.
|
|
217
|
+
*/
|
|
218
|
+
export const deleteFacet = (filePath: string, facetKey: string): DeployConfig => {
|
|
219
|
+
const deployConfig = readDeployConfig(filePath);
|
|
220
|
+
delete deployConfig.facets[facetKey];
|
|
221
|
+
saveDeployConfig(filePath, deployConfig);
|
|
222
|
+
return deployConfig;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Validates that the facets file exists, is valid JSON, and conforms to the schema.
|
|
227
|
+
* @param filePath - The path to the facets file.
|
|
228
|
+
* @returns A boolean indicating whether the file is valid.
|
|
229
|
+
*/
|
|
230
|
+
export const validateDeployConfig = (filePath: string): boolean => {
|
|
231
|
+
try {
|
|
232
|
+
const fullPath = resolvePath(filePath);
|
|
233
|
+
|
|
234
|
+
// Check if the file exists
|
|
235
|
+
if (!existsSync(fullPath)) {
|
|
236
|
+
console.error(`Validation failed: File does not exist at path "${filePath}"`);
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Read the file and parse it as JSON
|
|
241
|
+
const raw = readJsonSync(fullPath);
|
|
242
|
+
|
|
243
|
+
// Validate the JSON against the schema
|
|
244
|
+
DeployConfigSchema.parse(raw);
|
|
245
|
+
|
|
246
|
+
// If all checks pass, return true
|
|
247
|
+
return true;
|
|
248
|
+
} catch (e) {
|
|
249
|
+
console.error('Validation failed:', e);
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// // databaseHandler.ts (Prisma example)
|
|
2
|
+
// import { prisma } from './prisma';
|
|
3
|
+
// import { DeployedDiamondData, DeployConfig } from '../schemas';
|
|
4
|
+
|
|
5
|
+
// export async function readDeployedDiamondData(network: string, diamond: string): Promise<DeployedDiamondData> {
|
|
6
|
+
// const record = await prisma.deployment.findUnique({
|
|
7
|
+
// where: { network_diamond: { network, diamond } }
|
|
8
|
+
// });
|
|
9
|
+
// return record?.info as DeployedDiamondData;
|
|
10
|
+
// }
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Schema for a single facet's deployment information
|
|
4
|
+
export const DeployedFacetSchema = z.object({
|
|
5
|
+
address: z.string().optional(), // Address of the deployed facet
|
|
6
|
+
tx_hash: z.string().optional(), // Transaction hash of the deployment
|
|
7
|
+
version: z.number().optional(), // Version of the facet
|
|
8
|
+
funcSelectors: z.array(z.string()).optional(), // Function selectors for the facet
|
|
9
|
+
verified: z.boolean().optional(), // Whether the facet is verified
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// Schema for all deployed facets
|
|
13
|
+
export const DeployedFacetsSchema = z.record(z.string(), DeployedFacetSchema);
|
|
14
|
+
|
|
15
|
+
// Schema for external libraries
|
|
16
|
+
export const ExternalLibrariesSchema = z.record(z.string(), z.string());
|
|
17
|
+
|
|
18
|
+
// Schema for the network deployment information
|
|
19
|
+
export const DeployedDiamondDataSchema = z.object({
|
|
20
|
+
DiamondAddress: z.string().optional(), // Address of the deployed diamond
|
|
21
|
+
DeployerAddress: z.string().optional(), // Address of the deployer
|
|
22
|
+
// FacetDeployedInfo: FacetDeployedInfoRecordSchema.optional(), // Information about deployed facets
|
|
23
|
+
DeployedFacets: DeployedFacetsSchema.optional(), // Information about deployed facets
|
|
24
|
+
ExternalLibraries: ExternalLibrariesSchema.optional(), // External libraries used in the deployment
|
|
25
|
+
protocolVersion: z.number().optional(), // Protocol version
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Schema for the version information of a facet configuration to be deployed
|
|
30
|
+
*/
|
|
31
|
+
export const FacetVersionConfigSchema = z.object({
|
|
32
|
+
deployInit: z.string().optional(),
|
|
33
|
+
upgradeInit: z.string().optional(),
|
|
34
|
+
fromVersions: z.array(z.number()).optional(),
|
|
35
|
+
callbacks: z.array(z.string()).optional(),
|
|
36
|
+
deployInclude: z.array(z.string()).optional(),
|
|
37
|
+
deployExclude: z.array(z.string()).optional(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Schema for the deployment information of a single facet
|
|
42
|
+
*/
|
|
43
|
+
export const FacetConfigSchema = z.object({
|
|
44
|
+
// Infer TypeScript types from schemas
|
|
45
|
+
priority: z.number(),
|
|
46
|
+
libraries: z.array(z.string()).optional(),
|
|
47
|
+
versions: z.record(z.string(), FacetVersionConfigSchema).optional(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Schema for the deployment configuration information of ALL facets to be deployed
|
|
52
|
+
*/
|
|
53
|
+
export const FacetsConfigSchema = z.record(z.string(), FacetConfigSchema);
|
|
54
|
+
|
|
55
|
+
export const DeployConfigSchema = z.object({
|
|
56
|
+
protocolVersion: z.number(),
|
|
57
|
+
protocolInitFacet: z.string().optional(),
|
|
58
|
+
protocolCallback: z.string().optional(),
|
|
59
|
+
facets: z.record(z.string(), FacetConfigSchema),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Inferred types from Zod schemas
|
|
63
|
+
export type FacetVersionConfig = z.infer<typeof FacetVersionConfigSchema>;
|
|
64
|
+
export type FacetConfig = z.infer<typeof FacetConfigSchema>;
|
|
65
|
+
export type FacetsConfig = z.infer<typeof FacetsConfigSchema>;
|
|
66
|
+
export type DeployConfig = z.infer<typeof DeployConfigSchema>;
|
|
67
|
+
|
|
68
|
+
// export type FacetsDeployment = z.infer<typeof FacetsConfigSchema>;
|
|
69
|
+
export type DeployedFacet = z.infer<typeof DeployedFacetSchema>;
|
|
70
|
+
export type DeployedFacets = z.infer<typeof DeployedFacetsSchema>;
|
|
71
|
+
export type DeployedDiamondData = z.infer<typeof DeployedDiamondDataSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DeploymentSchema';
|