-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(zksync): simplify artifact utility functions
- Loading branch information
1 parent
5d67367
commit 2c84dd0
Showing
1 changed file
with
8 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |