import { Address } from '@graphprotocol/graph-ts' ; import { setBlacklistedDAOs , setContractsInfo , setTemplatesInfo , } from '../../contractsInfo' ; import { DAOTracker , TrackDAO , } from '../../types/DAOTracker/DAOTracker' ; import { AvatarContract , BlacklistedDAO , ContractInfo , DAOTrackerContract , UControllerOrganization , } from '../../types/schema' ; import { createTemplate , equalStrings , fetchTemplateName } from '../../utils' ; export function getDAOTrackerContract ( address ) { let daoTracker = DAOTrackerContract . load ( address . toHex ( ) ) as DAOTrackerContract ; if ( daoTracker == null ) { daoTracker = new DAOTrackerContract ( address . toHex ( ) ) ; daoTracker . address = address ; let daoTrackerSC = DAOTracker . bind ( address ) ; daoTracker . owner = daoTrackerSC . owner ( ) ; daoTracker . save ( ) ; setBlacklistedDAOs ( ) ; setContractsInfo ( ) ; setTemplatesInfo ( ) ; } return daoTracker ; } export function handleTrackDAO ( event ) { getDAOTrackerContract ( event . address ) ; let avatar = event . params . _avatar ; let controller = event . params . _controller ; let reputation = event . params . _reputation ; let daoToken = event . params . _daoToken ; let sender = event . params . _sender ; let arcVersion = event . params . _arcVersion ; if ( AvatarContract . load ( avatar . toHex ( ) ) != null ) { return ; } if ( BlacklistedDAO . load ( avatar . toHex ( ) ) != null ) { return ; } let daoCreatorInfo = ContractInfo . load ( sender . toHex ( ) ) ; if ( daoCreatorInfo != null && equalStrings ( daoCreatorInfo . name , 'DaoCreator' ) ) { arcVersion = daoCreatorInfo . version ; } else { return ; } let avatarTemplate = fetchTemplateName ( 'Avatar' , arcVersion ) ; let controllerTemplate = fetchTemplateName ( 'Controller' , arcVersion ) ; let reputationTemplate = fetchTemplateName ( 'Reputation' , arcVersion ) ; let daoTokenTemplate = fetchTemplateName ( 'DAOToken' , arcVersion ) ; let missingTemplate = avatarTemplate == null || reputationTemplate == null || daoTokenTemplate == null ; let universalController = UControllerOrganization . load ( controller . toHex ( ) ) != null ; if ( universalController == false ) { missingTemplate = missingTemplate || controllerTemplate == null ; } if ( missingTemplate ) { return ; } createTemplate ( avatarTemplate , avatar ) ; createTemplate ( reputationTemplate , reputation ) ; createTemplate ( daoTokenTemplate , daoToken ) ; if ( universalController == false ) { createTemplate ( controllerTemplate , controller ) ; } }