import { Address } from '@graphprotocol/graph-ts' ; import { DeployDAO as DeployDAOEvent } from '../../generated/DaoFactory/DAOFactory' ; import { OrgFactory as FactoryEntity } from '../../generated/schema' ; import { Kernel as OrganizationTemplate } from '../../generated/templates' ; import { loadOrCreateOrg } from './organization' ; export function handleDeployDAO ( event ) { const factoryAddress = event . address ; const factory = loadOrCreateOrgFactory ( factoryAddress ) ; const orgAddress = event . params . dao ; const org = loadOrCreateOrg ( orgAddress , event . block . timestamp ) ; const currentOrganizations = factory . organizations ; currentOrganizations . push ( org . id ) ; factory . organizations = currentOrganizations ; factory . orgCount = factory . orgCount + 1 ; factory . save ( ) ; org . save ( ) ; OrganizationTemplate . create ( orgAddress ) ; } function loadOrCreateOrgFactory ( factoryAddress ) { let factory = FactoryEntity . load ( '1' ) ; if ( factory === null ) { factory = new FactoryEntity ( '1' ) ; factory . address = factoryAddress ; factory . orgCount = 0 ; factory . organizations = [ ] ; } return factory ! ; }