@@ -3,27 +3,48 @@ import { join, parse as parsePath } from 'node:path';
33
44import type { AddressLike } from 'ethers' ;
55
6- export interface DeploymentAddressEntry {
6+ export interface Deployment {
7+ deploymentName : string ; // The full deterministic name from the artifact file
78 address : AddressLike ;
89 constructorArgs ?: any [ ] ;
910 constructorArgTypes ?: string [ ] ;
1011}
1112
12- export interface ChainDeploymentAddresses {
13- [ chainId : string ] : DeploymentAddressEntry ;
13+ export interface DeploymentsByChain {
14+ [ chainId : string ] : Deployment [ ] ;
1415}
1516
16- export interface AllDeploymentAddresses {
17- [ deploymentName : string ] : ChainDeploymentAddresses ;
17+ export interface AllDeploymentsByContract {
18+ [ contractName : string ] : DeploymentsByChain ;
19+ }
20+
21+ // Helper to extract contract name from a deployment name
22+ function extractContractName ( deploymentName : string ) : string {
23+ if ( ! deploymentName ) return '' ;
24+
25+ const lastUnderscoreIndex = deploymentName . lastIndexOf ( '_' ) ;
26+ if ( lastUnderscoreIndex < 0 || lastUnderscoreIndex === deploymentName . length - 1 ) {
27+ return deploymentName ;
28+ }
29+
30+ const potentialSuffix = deploymentName . slice ( lastUnderscoreIndex + 1 ) ;
31+ if ( potentialSuffix . length === 8 && / ^ [ \d A - F a - f ] + $ / . test ( potentialSuffix ) ) {
32+ return deploymentName . slice ( 0 , lastUnderscoreIndex ) ;
33+ }
34+
35+ return deploymentName ;
1836}
1937
2038/**
2139 * Reads deployment artifacts from the `deployments` directory (specific to data-feed-proxy-combinators)
22- * and aggregates contract addresses, constructor arguments, and types by deployment name and chain ID.
40+ * and aggregates contract addresses, constructor arguments, and types by contract name, then by chain ID,
41+ * with an array of deployment instances.
2342 * @returns A stringified JSON object of deployment addresses.
2443 */
2544export function getDeploymentAddresses ( ) : string {
26- const allAddresses : AllDeploymentAddresses = { } ;
45+ const allDeployments : AllDeploymentsByContract = { } ;
46+ // Assumes this script is in data-feed-proxy-combinators/scripts/src/
47+ // and the deployments directory is at data-feed-proxy-combinators/deployments/
2748 const deploymentsRoot = join ( __dirname , '..' , '..' , 'deployments' ) ;
2849
2950 if ( ! fs . existsSync ( deploymentsRoot ) ) {
@@ -48,17 +69,26 @@ export function getDeploymentAddresses(): string {
4869
4970 for ( const deploymentFile of deploymentFiles ) {
5071 const deploymentName = parsePath ( deploymentFile ) . name ;
72+ const contractName = extractContractName ( deploymentName ) ;
73+
5174 const artifact = JSON . parse ( fs . readFileSync ( join ( networkPath , deploymentFile ) , 'utf8' ) ) ;
52- const constructorEntry = artifact . abi . find ( ( item : any ) => item . type === 'constructor' ) ;
53- const constructorArgTypes = constructorEntry ?. inputs ?. map ( ( input : any ) => input . type ) || [ ] ;
75+ const constructorEntry = artifact . abi ?. find (
76+ ( item : { type : string ; inputs ?: unknown [ ] } ) => item . type === 'constructor'
77+ ) ;
78+ const constructorArgTypes = constructorEntry ?. inputs ?. map ( ( input : { type : string } ) => input . type ) ?? [ ] ;
5479
55- if ( ! allAddresses [ deploymentName ] ) allAddresses [ deploymentName ] = { } ;
56- allAddresses [ deploymentName ] [ chainId ] = {
80+ const instanceDetail : Deployment = {
81+ deploymentName ,
5782 address : artifact . address ,
5883 constructorArgs : artifact . args || [ ] ,
5984 constructorArgTypes,
6085 } ;
86+
87+ allDeployments [ contractName ] = {
88+ ...allDeployments [ contractName ] ,
89+ [ chainId ] : [ ...( allDeployments [ contractName ] ?. [ chainId ] ?? [ ] ) , instanceDetail ] ,
90+ } ;
6191 }
6292 }
63- return `${ JSON . stringify ( allAddresses , null , 2 ) } \n` ;
93+ return `${ JSON . stringify ( allDeployments , null , 2 ) } \n` ;
6494}
0 commit comments