11import { ContractEvent , DEFAULT_MAPPING , SubgraphData } from 'hooks/local-subgraphs'
2- import { generateContractFile , generateSchemaFile } from './graph-file-generator'
2+ import { generateLibrariesForSubgraph } from './graph-file-generator'
33import Hash from 'ipfs-only-hash'
44
55export enum STATUS {
@@ -136,14 +136,7 @@ export async function prepareSubgraphDeploymentFiles(subgraph: SubgraphData) {
136136 throw new Error ( `Couldn't find event ${ signature } in ABI` )
137137 }
138138
139- const libraries : { [ name : string ] : string } = { }
140-
141- for ( const contract of subgraph . contracts ) {
142- const code = await generateContractFile ( contract . name , contract . abi )
143- libraries [ `contracts/${ contract . name } .ts` ] = code
144- }
145-
146- libraries [ 'schema/index.ts' ] = await generateSchemaFile ( subgraph . schema )
139+ const libraries = await generateLibrariesForSubgraph ( subgraph )
147140
148141 const compiled = await compileAs ( subgraph . mappings [ DEFAULT_MAPPING ] , libraries )
149142
@@ -166,6 +159,7 @@ export async function prepareSubgraphDeploymentFiles(subgraph: SubgraphData) {
166159 } )
167160
168161 const dataSources : any [ ] = [ ]
162+ const templates : any [ ] = [ ]
169163
170164 // Currently, all ABIs are available to all data sources, so we generate
171165 // one single array that's added to all sources
@@ -189,14 +183,12 @@ export async function prepareSubgraphDeploymentFiles(subgraph: SubgraphData) {
189183 cid,
190184 } )
191185
192- dataSources . push ( {
186+ const contractManifest : any = {
193187 kind : 'ethereum/contract' ,
194188 name : contract . name ,
195189 network : 'mainnet' ,
196190 source : {
197191 abi : contract . name ,
198- address : contract . addresses [ '1' ] ,
199- startBlock : contract . startBlocks [ '1' ] ,
200192 } ,
201193 mapping : {
202194 abis,
@@ -213,7 +205,15 @@ export async function prepareSubgraphDeploymentFiles(subgraph: SubgraphData) {
213205 kind : 'ethereum/events' ,
214206 language : 'wasm/assemblyscript' ,
215207 } ,
216- } )
208+ }
209+
210+ if ( contract . isTemplate ) {
211+ templates . push ( contractManifest )
212+ } else {
213+ contractManifest . source . address = contract . addresses [ '1' ]
214+ contractManifest . source . startBlock = contract . startBlocks [ '1' ]
215+ dataSources . push ( contractManifest )
216+ }
217217 }
218218
219219 const schemaCid = await getCID ( subgraph . schema )
@@ -225,23 +225,29 @@ export async function prepareSubgraphDeploymentFiles(subgraph: SubgraphData) {
225225 cid : schemaCid ,
226226 } )
227227
228- const manifestString = yaml . dump ( {
229- specVersion : '0.0.5' ,
230- description : 'Test description' ,
231- dataSources,
232- schema : {
233- file : {
234- '/' : `/ipfs/${ schemaCid } ` ,
228+ const manifestString = yaml . dump (
229+ {
230+ specVersion : '0.0.5' ,
231+ description : 'Test description' ,
232+ dataSources,
233+ templates,
234+ schema : {
235+ file : {
236+ '/' : `/ipfs/${ schemaCid } ` ,
237+ } ,
235238 } ,
239+ sourceCode : [
240+ {
241+ name : 'mapping.ts' ,
242+ file : `/ipfs/${ mappingCid } ` ,
243+ source : `/ipfs/${ sourceCid } ` ,
244+ } ,
245+ ] ,
236246 } ,
237- sourceCode : [
238- {
239- name : 'mapping.ts' ,
240- file : `/ipfs/${ mappingCid } ` ,
241- source : `/ipfs/${ sourceCid } ` ,
242- } ,
243- ] ,
244- } )
247+ {
248+ noRefs : true ,
249+ }
250+ )
245251
246252 files . push ( {
247253 title : 'Manifest' ,
0 commit comments