Skip to content

Commit

Permalink
refactor(zksync): simplify artifact utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Jan 27, 2025
1 parent 5d67367 commit 2c84dd0
Showing 1 changed file with 8 additions and 43 deletions.
51 changes: 8 additions & 43 deletions solidity/core-utils/zksync/utils.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
import { zkSyncContractArtifacts } from './artifacts.js';
import { ZKSyncArtifact } from './types.js';

type ArtifactMap = Record<string, ZKSyncArtifact>;

/**
* @dev Exports the list of artifact names.
* @return An array of artifact names.
*/
export async function getZKSyncArtifactNames(): Promise<string[]> {
return zkSyncContractArtifacts.map((artifact) => artifact.contractName);
}

/**
* @dev Checks if a ZkSync artifact exists by its name.
* @param name The name of the artifact to check.
* @return True if the artifact exists, false otherwise.
*/
export async function artifactExists(name: string): Promise<boolean> {
return zkSyncContractArtifacts.some(
(artifact) => artifact.contractName === name,
);
}

/**
* @dev Loads a ZkSync artifact by its name.
* @param name The name of the artifact to load.
* @dev Get a ZkSync artifact by its name.
* @param name The name of the artifact to get.
* @return The loaded ZKSyncArtifact or undefined if it cannot be found.
*/
export async function loadZKSyncArtifact(
export function getZKSyncArtifactByName(
name: string,
): Promise<ZKSyncArtifact | undefined> {
): ZKSyncArtifact | undefined {
return zkSyncContractArtifacts.find(
(artifact) => artifact.contractName === name,
);
}

/**
* @dev Loads all ZkSync artifacts into a map.
* @return A map of artifact names to their corresponding ZkSync artifacts.
*/
export async function loadAllZKSyncArtifacts(): Promise<ArtifactMap> {
return zkSyncContractArtifacts.reduce((map, artifact) => {
map[artifact.contractName] = artifact;
return map;
}, {} as ArtifactMap);
}

/**
* @dev Retrieves a specific ZkSync artifact by its name.
* @param name The name of the artifact to retrieve.
* @return The ZkSyncArtifact or undefined if it cannot be found.
* @dev Loads all ZkSync artifacts into an array.
* @return An array of ZkSync artifacts.
*/
export async function getZKSyncArtifactByName(
name: string,
): Promise<ZKSyncArtifact | undefined> {
return loadZKSyncArtifact(name);
export function loadAllZKSyncArtifacts(): ZKSyncArtifact[] {
return zkSyncContractArtifacts;
}

0 comments on commit 2c84dd0

Please sign in to comment.