import { Address , BigInt , ByteArray , Bytes , crypto } from '@graphprotocol/graph-ts' ; import { Event , Proposal , ReputationHolder } from '../types/schema' ; import { concat , fixJsonQuotes } from '../utils' ; export function addNewDAOEvent ( avatar , daoName , timestamp ) { addEvent ( 'NewDAO' , avatar . toHex ( ) , '{ "name": "' + fixJsonQuotes ( daoName ) + '" }' , null , null , avatar . toHex ( ) , timestamp ) ; } export function addProposalStateChangeEvent ( proposalId , user , timestamp ) { let proposal = Proposal . load ( proposalId . toHex ( ) ) ; addEvent ( 'ProposalStageChange' , crypto . keccak256 ( concat ( proposalId , timestamp as ByteArray ) ) . toHex ( ) , '{ "stage": "' + proposal . stage + '" }' , proposalId . toHex ( ) , user , proposal . dao , timestamp ) ; } export function addNewReputationHolderEvent ( reputationHolder ) { addEvent ( 'NewReputationHolder' , crypto . keccak256 ( concat ( reputationHolder . address , reputationHolder . createdAt as ByteArray ) ) . toHex ( ) , '{ "reputationAmount": "' + reputationHolder . balance . toString ( ) + '" }' , null , reputationHolder . address , reputationHolder . dao , reputationHolder . createdAt ) ; } export function addVoteFlipEvent ( proposalId , proposal , voter , timestamp ) { addEvent ( 'VoteFlip' , crypto . keccak256 ( concat ( concat ( proposalId , proposal . votesFor as ByteArray ) , proposal . votesAgainst as ByteArray ) ) . toHex ( ) , '{ "outcome": "' + proposal . winningOutcome + '", "votesFor": "' + proposal . votesFor . toString ( ) + '", "votesAgainst": "' + proposal . votesAgainst . toString ( ) + '" }' , proposalId . toHex ( ) , voter , proposal . dao , timestamp ) ; } export function addNewProposalEvent ( proposalId , proposal , timestamp ) { addEvent ( 'NewProposal' , crypto . keccak256 ( concat ( proposalId , timestamp as ByteArray ) ) . toHex ( ) , '{ "title": "' + fixJsonQuotes ( proposal . title ) + '" }' , proposalId . toHex ( ) , proposal . proposer , proposal . dao , timestamp ) ; } export function addStakeEvent ( eventId , proposalId , outcome , amount , staker , daoId , timestamp ) { addEvent ( 'Stake' , eventId , '{ "outcome": "' + outcome + '", "stakeAmount": "' + amount . toString ( ) + '" }' , proposalId , staker , daoId , timestamp ) ; } export function addVoteEvent ( eventId , proposalId , outcome , reputation , voter , daoId , timestamp ) { addEvent ( 'Vote' , eventId , '{ "outcome": "' + outcome + '", "reputationAmount": "' + reputation . toString ( ) + '" }' , proposalId , voter , daoId , timestamp ) ; } function addEvent ( type , id , data , proposal , user , dao , timestamp ) { let eventEnt = new Event ( id ) ; eventEnt . type = type ; eventEnt . data = data ; eventEnt . proposal = proposal ; eventEnt . user = user ; eventEnt . dao = dao ; eventEnt . timestamp = timestamp ; eventEnt . save ( ) ; }