dispenser updates (#341)

This commit is contained in:
Alex Coseru 2022-02-20 14:36:26 +02:00 committed by GitHub
parent cbdbc64a42
commit 68db058782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View File

@ -11,7 +11,7 @@ import { decimal } from './utils/constants'
import { import {
getDispenser, getDispenser,
getDispenserGraphID, getDispenserGraphID,
updateDispenserBalance updateDispenserDetails
} from './utils/dispenserUtils' } from './utils/dispenserUtils'
import { weiToDecimal } from './utils/generic' import { weiToDecimal } from './utils/generic'
import { addDispenser } from './utils/globalUtils' import { addDispenser } from './utils/globalUtils'
@ -45,6 +45,7 @@ export function handleNewDispenser(event: DispenserCreated): void {
dispenser.save() dispenser.save()
addDispenser() addDispenser()
updateDispenserDetails(event.address, event.params.datatokenAddress)
} }
export function handleActivate(event: DispenserActivated): void { export function handleActivate(event: DispenserActivated): void {
@ -88,13 +89,7 @@ export function handleTokensDispensed(event: TokensDispensed): void {
const dispenserTransaction = new DispenserTransaction(id) const dispenserTransaction = new DispenserTransaction(id)
const dispenser = getDispenser(dispenserID) const dispenser = getDispenser(dispenserID)
dispenser.balance = updateDispenserBalance( updateDispenserDetails(event.address, event.params.datatokenAddress)
event.address,
event.params.datatokenAddress
)
dispenser.save()
dispenserTransaction.dispenser = dispenser.id dispenserTransaction.dispenser = dispenser.id
const user = getUser(event.params.userAddress.toHex()) const user = getUser(event.params.userAddress.toHex())
dispenserTransaction.user = user.id dispenserTransaction.user = user.id

View File

@ -1,6 +1,6 @@
import { Dispenser } from '../../@types/schema' import { Dispenser } from '../../@types/schema'
import { getToken } from './tokenUtils' import { getToken } from './tokenUtils'
import { Address, BigDecimal } from '@graphprotocol/graph-ts' import { Address } from '@graphprotocol/graph-ts'
import { weiToDecimal } from './generic' import { weiToDecimal } from './generic'
import { Dispenser as DispenserContract } from '../../@types/Dispenser/Dispenser' import { Dispenser as DispenserContract } from '../../@types/Dispenser/Dispenser'
@ -25,16 +25,21 @@ export function getDispenser(dispenserID: string): Dispenser {
return dispenser return dispenser
} }
export function updateDispenserBalance( export function updateDispenserDetails(
contractAddress: Address, contractAddress: Address,
datatokenAddress: Address datatokenAddress: Address
): BigDecimal { ): void {
const dispenserID = getDispenserGraphID(contractAddress, datatokenAddress)
const dispenser = getDispenser(dispenserID)
const contract = DispenserContract.bind(contractAddress) const contract = DispenserContract.bind(contractAddress)
const dispenserDetails = contract.try_status(datatokenAddress) const dispenserDetails = contract.try_status(datatokenAddress)
if (dispenserDetails == null) return BigDecimal.fromString('0') if (dispenserDetails == null) return
const token = getToken(datatokenAddress, true) const token = getToken(datatokenAddress, true)
return weiToDecimal( dispenser.balance = weiToDecimal(
dispenserDetails.value.value5.toBigDecimal(), dispenserDetails.value.value5.toBigDecimal(),
token.decimals token.decimals
) )
dispenser.isMinter = dispenserDetails.value.value2
dispenser.active = dispenserDetails.value.value0
dispenser.save()
} }