@@ -612,6 +612,7 @@ async function processInitForm(
612
612
}
613
613
614
614
// If ABI is not provided, try to fetch it from Etherscan API
615
+ let implAddress : string | undefined = undefined ;
615
616
if ( protocolInstance . hasABIs ( ) && ! initAbi ) {
616
617
abiFromApi = await retryWithPrompt ( ( ) =>
617
618
withSpinner (
@@ -622,15 +623,50 @@ async function processInitForm(
622
623
) ,
623
624
) ;
624
625
initDebugger . extend ( 'processInitForm' ) ( "abiFromEtherscan len: '%s'" , abiFromApi ?. name ) ;
626
+ const isProxy =
627
+ abiFromApi ?. callFunctions ( ) . some ( entry => entry . get ( 'name' ) === 'implementation' ) ??
628
+ false ;
629
+ initDebugger . extend ( 'processInitForm' ) ( 'isProxy: %O' , isProxy ) ;
630
+ if ( isProxy ) {
631
+ const impl = await retryWithPrompt ( ( ) =>
632
+ withSpinner (
633
+ 'Fetching proxy implementation address...' ,
634
+ 'Failed to fetch proxy implementation address' ,
635
+ 'Warning fetching proxy implementation address' ,
636
+ ( ) => contractService . getProxyImplementation ( network . id , address ) ,
637
+ ) ,
638
+ ) ;
639
+ initDebugger . extend ( 'processInitForm' ) ( "proxyImplementation: '%s'" , impl ) ;
640
+ if ( impl ) {
641
+ const useImplementation = await prompt . confirm (
642
+ `Proxy contract detected. Index implementation contract at ${ impl } ?` ,
643
+ true ,
644
+ ) ;
645
+
646
+ if ( useImplementation ) {
647
+ implAddress = impl ;
648
+ abiFromApi = await retryWithPrompt ( ( ) =>
649
+ withSpinner (
650
+ 'Fetching implementation contract ABI...' ,
651
+ 'Failed to fetch implementation ABI' ,
652
+ 'Warning fetching implementation ABI' ,
653
+ ( ) =>
654
+ contractService . getABI ( protocolInstance . getABI ( ) , network . id , implAddress ! ) ,
655
+ ) ,
656
+ ) ;
657
+ }
658
+ }
659
+ }
625
660
}
661
+
626
662
// If startBlock is not provided, try to fetch it from Etherscan API
627
663
if ( ! initStartBlock ) {
628
664
startBlock = await retryWithPrompt ( ( ) =>
629
665
withSpinner (
630
666
'Fetching start block from contract API...' ,
631
667
'Failed to fetch start block' ,
632
668
'Warning fetching start block' ,
633
- ( ) => contractService . getStartBlock ( network . id , address ) ,
669
+ ( ) => contractService . getStartBlock ( network . id , implAddress ?? address ) ,
634
670
) ,
635
671
) ;
636
672
initDebugger . extend ( 'processInitForm' ) ( "startBlockFromEtherscan: '%s'" , startBlock ) ;
@@ -643,7 +679,7 @@ async function processInitForm(
643
679
'Fetching contract name from contract API...' ,
644
680
'Failed to fetch contract name' ,
645
681
'Warning fetching contract name' ,
646
- ( ) => contractService . getContractName ( network . id , address ) ,
682
+ ( ) => contractService . getContractName ( network . id , implAddress ?? address ) ,
647
683
) ,
648
684
) ;
649
685
initDebugger . extend ( 'processInitForm' ) ( "contractNameFromEtherscan: '%s'" , contractName ) ;
0 commit comments