@@ -84,7 +84,8 @@ export default class AddCommand extends Command {
84
84
let startBlock = startBlockFlag ? parseInt ( startBlockFlag ) . toString ( ) : startBlockFlag ;
85
85
let contractName = contractNameFlag || DEFAULT_CONTRACT_NAME ;
86
86
87
- let ethabi = null ;
87
+ let ethabi : EthereumABI | null = null ;
88
+ let implAddress = null ;
88
89
if ( abi ) {
89
90
ethabi = EthereumABI . load ( contractName , abi ) ;
90
91
} else {
@@ -100,6 +101,36 @@ export default class AddCommand extends Command {
100
101
) ,
101
102
) ;
102
103
if ( ! ethabi ) throw Error ;
104
+ const isProxy = ethabi . callFunctionSignatures ( ) ?. includes ( 'upgradeTo(address)' ) ;
105
+ if ( isProxy ) {
106
+ const impl = await retryWithPrompt ( ( ) =>
107
+ withSpinner (
108
+ 'Fetching proxy implementation address...' ,
109
+ 'Failed to fetch proxy implementation address' ,
110
+ 'Warning fetching proxy implementation address' ,
111
+ ( ) => contractService . getProxyImplementation ( network , address ) ,
112
+ ) ,
113
+ ) ;
114
+ if ( impl ) {
115
+ const useImplementation = await prompt . confirm (
116
+ `Proxy contract detected. Index implementation contract at ${ impl } ?` ,
117
+ true ,
118
+ ) ;
119
+
120
+ if ( useImplementation ) {
121
+ implAddress = impl ;
122
+ ethabi = await retryWithPrompt ( ( ) =>
123
+ withSpinner (
124
+ 'Fetching implementation contract ABI...' ,
125
+ 'Failed to fetch implementation ABI' ,
126
+ 'Warning fetching implementation ABI' ,
127
+ ( ) => contractService . getABI ( EthereumABI , network , implAddress ! ) ,
128
+ ) ,
129
+ ) ;
130
+ }
131
+ if ( ! ethabi ) throw Error ;
132
+ }
133
+ }
103
134
} catch ( error ) {
104
135
// we cannot ask user to do prompt in test environment
105
136
if ( process . env . NODE_ENV !== 'test' ) {
@@ -122,10 +153,15 @@ export default class AddCommand extends Command {
122
153
}
123
154
}
124
155
}
156
+ if ( ! ethabi ) {
157
+ this . error ( 'Failed to load ABI' , { exit : 1 } ) ;
158
+ }
125
159
126
160
try {
127
161
if ( isLocalHost ) throw Error ; // Triggers user prompting without waiting for Etherscan lookup to fail
128
- startBlock ||= Number ( await contractService . getStartBlock ( network , address ) ) . toString ( ) ;
162
+ startBlock ||= Number (
163
+ await contractService . getStartBlock ( network , implAddress ?? address ) ,
164
+ ) . toString ( ) ;
129
165
} catch ( error ) {
130
166
// we cannot ask user to do prompt in test environment
131
167
if ( process . env . NODE_ENV !== 'test' ) {
@@ -150,7 +186,8 @@ export default class AddCommand extends Command {
150
186
if ( isLocalHost ) throw Error ; // Triggers user prompting without waiting for Etherscan lookup to fail
151
187
if ( contractName === DEFAULT_CONTRACT_NAME ) {
152
188
contractName =
153
- ( await contractService . getContractName ( network , address ) ) ?? DEFAULT_CONTRACT_NAME ;
189
+ ( await contractService . getContractName ( network , implAddress ?? address ) ) ??
190
+ DEFAULT_CONTRACT_NAME ;
154
191
}
155
192
} catch ( error ) {
156
193
// not asking user to do prompt in test environment
@@ -248,8 +285,6 @@ export default class AddCommand extends Command {
248
285
'Warning during codegen' ,
249
286
async ( ) => await system . run ( yarn ? 'yarn codegen' : 'npm run codegen' ) ,
250
287
) ;
251
-
252
- this . exit ( 0 ) ;
253
288
}
254
289
}
255
290
0 commit comments