import { Address , BigInt , store } from '@graphprotocol/graph-ts' ; import { Avatar } from '../types/Controller/Avatar' ; import { DAO } from '../types/schema' ; export function getDAO ( id ) { let dao = store . get ( 'DAO' , id ) as DAO ; if ( dao == null ) { dao = new DAO ( id ) ; dao . numberOfQueuedProposals = BigInt . fromI32 ( 0 ) ; dao . numberOfPreBoostedProposals = BigInt . fromI32 ( 0 ) ; dao . numberOfBoostedProposals = BigInt . fromI32 ( 0 ) ; dao . numberOfExpiredInQueueProposals = BigInt . fromI32 ( 0 ) ; } return dao ; } export function increaseDAOmembersCount ( id ) { let dao = getDAO ( id ) ; dao . reputationHoldersCount = dao . reputationHoldersCount . plus ( BigInt . fromI32 ( 1 ) ) ; saveDAO ( dao ) ; } export function decreaseDAOmembersCount ( id ) { let dao = getDAO ( id ) ; dao . reputationHoldersCount = dao . reputationHoldersCount . minus ( BigInt . fromI32 ( 1 ) ) ; saveDAO ( dao ) ; } export function saveDAO ( dao ) { store . set ( 'DAO' , dao . id , dao ) ; } export function insertNewDAO ( avatarAddress , nativeTokenAddress , nativeReputationAddress ) { let avatar = Avatar . bind ( avatarAddress ) ; let dao = getDAO ( avatarAddress . toHex ( ) ) ; dao . name = avatar . orgName ( ) . toString ( ) ; dao . avatarContract = avatarAddress . toHex ( ) ; dao . nativeToken = nativeTokenAddress . toHex ( ) ; dao . nativeReputation = nativeReputationAddress . toHex ( ) ; dao . reputationHoldersCount = BigInt . fromI32 ( 0 ) ; dao . register = 'na' ; saveDAO ( dao ) ; return dao ; } export function register ( avatar , tag ) { let dao = DAO . load ( avatar . toHex ( ) ) ; if ( dao != null ) { dao . register = tag ; dao . save ( ) ; } } export function exists ( avatar ) { return ( DAO . load ( avatar . toHex ( ) ) != null ) ; }