mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
dispenser updates (#341)
This commit is contained in:
parent
cbdbc64a42
commit
68db058782
@ -11,7 +11,7 @@ import { decimal } from './utils/constants'
|
||||
import {
|
||||
getDispenser,
|
||||
getDispenserGraphID,
|
||||
updateDispenserBalance
|
||||
updateDispenserDetails
|
||||
} from './utils/dispenserUtils'
|
||||
import { weiToDecimal } from './utils/generic'
|
||||
import { addDispenser } from './utils/globalUtils'
|
||||
@ -45,6 +45,7 @@ export function handleNewDispenser(event: DispenserCreated): void {
|
||||
dispenser.save()
|
||||
|
||||
addDispenser()
|
||||
updateDispenserDetails(event.address, event.params.datatokenAddress)
|
||||
}
|
||||
|
||||
export function handleActivate(event: DispenserActivated): void {
|
||||
@ -88,13 +89,7 @@ export function handleTokensDispensed(event: TokensDispensed): void {
|
||||
|
||||
const dispenserTransaction = new DispenserTransaction(id)
|
||||
const dispenser = getDispenser(dispenserID)
|
||||
dispenser.balance = updateDispenserBalance(
|
||||
event.address,
|
||||
event.params.datatokenAddress
|
||||
)
|
||||
|
||||
dispenser.save()
|
||||
|
||||
updateDispenserDetails(event.address, event.params.datatokenAddress)
|
||||
dispenserTransaction.dispenser = dispenser.id
|
||||
const user = getUser(event.params.userAddress.toHex())
|
||||
dispenserTransaction.user = user.id
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Dispenser } from '../../@types/schema'
|
||||
import { getToken } from './tokenUtils'
|
||||
import { Address, BigDecimal } from '@graphprotocol/graph-ts'
|
||||
import { Address } from '@graphprotocol/graph-ts'
|
||||
import { weiToDecimal } from './generic'
|
||||
import { Dispenser as DispenserContract } from '../../@types/Dispenser/Dispenser'
|
||||
|
||||
@ -25,16 +25,21 @@ export function getDispenser(dispenserID: string): Dispenser {
|
||||
return dispenser
|
||||
}
|
||||
|
||||
export function updateDispenserBalance(
|
||||
export function updateDispenserDetails(
|
||||
contractAddress: Address,
|
||||
datatokenAddress: Address
|
||||
): BigDecimal {
|
||||
): void {
|
||||
const dispenserID = getDispenserGraphID(contractAddress, datatokenAddress)
|
||||
const dispenser = getDispenser(dispenserID)
|
||||
const contract = DispenserContract.bind(contractAddress)
|
||||
const dispenserDetails = contract.try_status(datatokenAddress)
|
||||
if (dispenserDetails == null) return BigDecimal.fromString('0')
|
||||
if (dispenserDetails == null) return
|
||||
const token = getToken(datatokenAddress, true)
|
||||
return weiToDecimal(
|
||||
dispenser.balance = weiToDecimal(
|
||||
dispenserDetails.value.value5.toBigDecimal(),
|
||||
token.decimals
|
||||
)
|
||||
dispenser.isMinter = dispenserDetails.value.value2
|
||||
dispenser.active = dispenserDetails.value.value0
|
||||
dispenser.save()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user