@@ -2,6 +2,7 @@ import fs from 'node:fs';
22import os from 'node:os' ;
33import path from 'node:path' ;
44import { filesystem , print , prompt , system } from 'gluegun' ;
5+ import immutable from 'immutable' ;
56import { Args , Command , Flags } from '@oclif/core' ;
67import { Network } from '@pinax/graph-networks-registry' ;
78import { appendApiVersionForGraph } from '../command-helpers/compiler.js' ;
@@ -200,6 +201,11 @@ export default class InitCommand extends Command {
200201 if ( ( fromContract || spkgPath ) && protocol && subgraphName && directory && network && node ) {
201202 const registry = await loadRegistry ( ) ;
202203 const contractService = new ContractService ( registry ) ;
204+ const sourcifyContractInfo = await contractService . getFromSourcify (
205+ EthereumABI ,
206+ network ,
207+ fromContract ! ,
208+ ) ;
203209
204210 if ( ! protocolChoices . includes ( protocol as ProtocolName ) ) {
205211 this . error (
@@ -222,7 +228,13 @@ export default class InitCommand extends Command {
222228 }
223229 } else {
224230 try {
225- abi = await contractService . getABI ( ABI , network , fromContract ! ) ;
231+ abi = sourcifyContractInfo
232+ ? new EthereumABI (
233+ DEFAULT_CONTRACT_NAME ,
234+ undefined ,
235+ immutable . fromJS ( sourcifyContractInfo . abi ) ,
236+ )
237+ : await contractService . getABI ( ABI , network , fromContract ! ) ;
226238 } catch ( e ) {
227239 this . exit ( 1 ) ;
228240 }
@@ -448,7 +460,7 @@ async function processInitForm(
448460 ] ;
449461 } ;
450462
451- let network = networks [ 0 ] ;
463+ let network : Network = networks [ 0 ] ;
452464 let protocolInstance : Protocol = new Protocol ( 'ethereum' ) ;
453465 let isComposedSubgraph = false ;
454466 let isSubstreams = false ;
@@ -611,6 +623,22 @@ async function processInitForm(
611623 return address ;
612624 }
613625
626+ const sourcifyContractInfo = await contractService . getFromSourcify (
627+ EthereumABI ,
628+ network . id ,
629+ address ,
630+ ) ;
631+ if ( sourcifyContractInfo ) {
632+ initStartBlock ??= sourcifyContractInfo . startBlock ;
633+ initContractName ??= sourcifyContractInfo . name ;
634+ initAbi ??= sourcifyContractInfo . abi ;
635+ initDebugger . extend ( 'processInitForm' ) (
636+ "infoFromSourcify: '%s'/'%s'" ,
637+ initStartBlock ,
638+ initContractName
639+ ) ;
640+ }
641+
614642 // If ABI is not provided, try to fetch it from Etherscan API
615643 if ( protocolInstance . hasABIs ( ) && ! initAbi ) {
616644 abiFromApi = await retryWithPrompt ( ( ) =>
@@ -622,6 +650,8 @@ async function processInitForm(
622650 ) ,
623651 ) ;
624652 initDebugger . extend ( 'processInitForm' ) ( "abiFromEtherscan len: '%s'" , abiFromApi ?. name ) ;
653+ } else {
654+ abiFromApi = initAbi ;
625655 }
626656 // If startBlock is not provided, try to fetch it from Etherscan API
627657 if ( ! initStartBlock ) {
0 commit comments