@@ -11,6 +11,7 @@ import { DEFAULT_IPFS_URL } from '../command-helpers/ipfs.js';
11
11
import { initNetworksConfig } from '../command-helpers/network.js' ;
12
12
import { chooseNodeUrl } from '../command-helpers/node.js' ;
13
13
import { PromptManager } from '../command-helpers/prompt-manager.js' ;
14
+ import { checkForProxy } from '../command-helpers/proxy.js' ;
14
15
import { loadRegistry } from '../command-helpers/registry.js' ;
15
16
import { retryWithPrompt } from '../command-helpers/retry.js' ;
16
17
import { generateScaffold , writeScaffold } from '../command-helpers/scaffold.js' ;
@@ -645,49 +646,26 @@ async function processInitForm(
645
646
( ) => contractService . getABI ( protocolInstance . getABI ( ) , network . id , address ) ,
646
647
) ,
647
648
) ;
648
- initDebugger . extend ( 'processInitForm' ) ( "abiFromEtherscan len : '%s'" , abiFromApi ?. name ) ;
649
+ initDebugger . extend ( 'processInitForm' ) ( "ABI : '%s'" , abiFromApi ?. name ) ;
649
650
} else {
650
651
abiFromApi = initAbi ;
651
652
}
652
653
653
- const isProxy =
654
- abiFromApi
655
- ?. callFunctions ( )
656
- . some (
657
- entry => entry . get ( 'name' ) === 'implementation' || entry . get ( 'name' ) === 'upgradeTo' ,
658
- ) ?? false ;
659
- initDebugger . extend ( 'processInitForm' ) ( 'isProxy: %O' , isProxy ) ;
660
-
661
- if ( isProxy ) {
662
- const impl = await retryWithPrompt ( ( ) =>
663
- withSpinner (
664
- 'Fetching proxy implementation address...' ,
665
- 'Failed to fetch proxy implementation address' ,
666
- 'Warning fetching proxy implementation address' ,
667
- ( ) => contractService . getProxyImplementation ( network . id , address ) ,
668
- ) ,
654
+ if ( abiFromApi ) {
655
+ const { implementationAbi, implementationAddress } = await checkForProxy (
656
+ contractService ,
657
+ network . id ,
658
+ address ,
659
+ abiFromApi ,
669
660
) ;
670
- initDebugger . extend ( 'processInitForm' ) ( "proxyImplementation: '%s'" , impl ) ;
671
- if ( impl ) {
672
- try {
673
- const useImplementation = await prompt . confirm (
674
- `Proxy contract detected. Use implementation contract ABI at ${ impl } ?` ,
675
- true ,
676
- ) ;
677
- if ( useImplementation ) {
678
- implAddress = impl ;
679
- abiFromApi = await retryWithPrompt ( ( ) =>
680
- withSpinner (
681
- 'Fetching implementation contract ABI...' ,
682
- 'Failed to fetch implementation ABI' ,
683
- 'Warning fetching implementation ABI' ,
684
- ( ) => contractService . getABI ( protocolInstance . getABI ( ) , network . id , implAddress ! ) ,
685
- ) ,
686
- ) ;
687
- }
688
- } catch ( error ) {
689
- this . error ( `Error confirming proxy implementation: ${ error . message } ` , { exit : 1 } ) ;
690
- }
661
+ if ( implementationAddress ) {
662
+ implAddress = implementationAddress ;
663
+ abiFromApi = implementationAbi ! ;
664
+ initDebugger . extend ( 'processInitForm' ) (
665
+ "Impl ABI: '%s', Impl Address: '%s'" ,
666
+ abiFromApi ?. name ,
667
+ implAddress ,
668
+ ) ;
691
669
}
692
670
}
693
671
0 commit comments