2021-11-10 13:47:44 +01:00
|
|
|
import {
|
|
|
|
DispenserActivated,
|
|
|
|
DispenserAllowedSwapperChanged,
|
|
|
|
DispenserDeactivated,
|
|
|
|
OwnerWithdrawed,
|
|
|
|
TokensDispensed
|
2022-02-21 11:45:24 +01:00
|
|
|
} from '../@types/templates/Dispenser/Dispenser'
|
2021-11-10 13:47:44 +01:00
|
|
|
import { DispenserCreated } from '../@types/ERC721Factory/ERC721Factory'
|
2022-01-13 17:24:57 +01:00
|
|
|
import { Dispenser, DispenserTransaction } from '../@types/schema'
|
2021-11-15 13:04:26 +01:00
|
|
|
import { decimal } from './utils/constants'
|
2022-02-20 09:00:16 +01:00
|
|
|
import {
|
|
|
|
getDispenser,
|
|
|
|
getDispenserGraphID,
|
2022-02-20 13:36:26 +01:00
|
|
|
updateDispenserDetails
|
2022-02-20 09:00:16 +01:00
|
|
|
} from './utils/dispenserUtils'
|
2022-01-13 17:24:57 +01:00
|
|
|
import { weiToDecimal } from './utils/generic'
|
2022-02-15 17:13:55 +01:00
|
|
|
import { addDispenser } from './utils/globalUtils'
|
2022-01-13 17:24:57 +01:00
|
|
|
import { getToken } from './utils/tokenUtils'
|
2021-11-10 13:47:44 +01:00
|
|
|
import { getUser } from './utils/userUtils'
|
2022-08-01 13:58:09 +02:00
|
|
|
import { BigDecimal } from '@graphprotocol/graph-ts'
|
2021-11-10 13:47:44 +01:00
|
|
|
|
|
|
|
export function handleNewDispenser(event: DispenserCreated): void {
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenserID = getDispenserGraphID(
|
|
|
|
event.address,
|
|
|
|
event.params.datatokenAddress
|
|
|
|
)
|
|
|
|
const dispenser = new Dispenser(dispenserID)
|
2022-02-18 12:09:18 +01:00
|
|
|
const token = getToken(event.params.datatokenAddress, false)
|
2022-01-13 17:24:57 +01:00
|
|
|
dispenser.token = token.id
|
2022-02-21 11:45:24 +01:00
|
|
|
dispenser.contract = event.address.toHexString()
|
2022-01-13 17:24:57 +01:00
|
|
|
|
|
|
|
dispenser.owner = event.params.owner.toHexString()
|
|
|
|
dispenser.maxBalance = weiToDecimal(
|
|
|
|
event.params.maxBalance.toBigDecimal(),
|
|
|
|
token.decimals
|
|
|
|
)
|
|
|
|
dispenser.maxTokens = weiToDecimal(
|
|
|
|
event.params.maxTokens.toBigDecimal(),
|
|
|
|
token.decimals
|
|
|
|
)
|
|
|
|
dispenser.active = true
|
2022-08-01 13:58:09 +02:00
|
|
|
dispenser.balance = BigDecimal.zero()
|
2022-01-13 17:24:57 +01:00
|
|
|
dispenser.allowedSwapper = event.params.allowedSwapper.toHex()
|
|
|
|
dispenser.createdTimestamp = event.block.timestamp.toI32()
|
|
|
|
dispenser.tx = event.transaction.hash.toHex()
|
2023-05-13 14:00:52 +02:00
|
|
|
dispenser.eventIndex = event.logIndex.toI32()
|
2022-01-13 17:24:57 +01:00
|
|
|
dispenser.block = event.block.number.toI32()
|
|
|
|
dispenser.save()
|
2022-02-15 17:13:55 +01:00
|
|
|
|
|
|
|
addDispenser()
|
2022-02-20 13:36:26 +01:00
|
|
|
updateDispenserDetails(event.address, event.params.datatokenAddress)
|
2021-11-10 13:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function handleActivate(event: DispenserActivated): void {
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenserID = getDispenserGraphID(
|
|
|
|
event.address,
|
|
|
|
event.params.datatokenAddress
|
|
|
|
)
|
|
|
|
const dispenser = getDispenser(dispenserID)
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.active = true
|
2023-05-13 14:00:52 +02:00
|
|
|
dispenser.eventIndex = event.logIndex.toI32()
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleDeactivate(event: DispenserDeactivated): void {
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenserID = getDispenserGraphID(
|
|
|
|
event.address,
|
|
|
|
event.params.datatokenAddress
|
|
|
|
)
|
|
|
|
const dispenser = getDispenser(dispenserID)
|
2022-08-12 09:32:48 +02:00
|
|
|
dispenser.active = false
|
2023-05-13 14:00:52 +02:00
|
|
|
dispenser.eventIndex = event.logIndex.toI32()
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleAllowedSwapperChanged(
|
|
|
|
event: DispenserAllowedSwapperChanged
|
|
|
|
): void {
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenserID = getDispenserGraphID(event.address, event.params.datatoken)
|
|
|
|
const dispenser = getDispenser(dispenserID)
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.allowedSwapper = event.params.newAllowedSwapper.toHex()
|
2023-05-13 14:00:52 +02:00
|
|
|
dispenser.eventIndex = event.logIndex.toI32()
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleTokensDispensed(event: TokensDispensed): void {
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenserID = getDispenserGraphID(
|
|
|
|
event.address,
|
|
|
|
event.params.datatokenAddress
|
|
|
|
)
|
2023-05-13 14:00:52 +02:00
|
|
|
const eventIndex: number = event.logIndex.toI32()
|
|
|
|
const id = `${event.transaction.hash.toHexString()}-${dispenserID}-${eventIndex}`
|
2021-11-10 13:47:44 +01:00
|
|
|
|
|
|
|
const dispenserTransaction = new DispenserTransaction(id)
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenser = getDispenser(dispenserID)
|
2022-02-20 13:36:26 +01:00
|
|
|
updateDispenserDetails(event.address, event.params.datatokenAddress)
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenserTransaction.dispenser = dispenser.id
|
|
|
|
const user = getUser(event.params.userAddress.toHex())
|
|
|
|
dispenserTransaction.user = user.id
|
|
|
|
|
|
|
|
dispenserTransaction.createdTimestamp = event.block.timestamp.toI32()
|
2021-12-02 12:08:47 +01:00
|
|
|
dispenserTransaction.tx = event.transaction.hash.toHex()
|
2023-05-13 14:00:52 +02:00
|
|
|
dispenserTransaction.eventIndex = event.logIndex.toI32()
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenserTransaction.block = event.block.number.toI32()
|
2022-02-20 09:00:16 +01:00
|
|
|
const token = getToken(event.params.datatokenAddress, true)
|
|
|
|
dispenserTransaction.amount = weiToDecimal(
|
|
|
|
event.params.amount.toBigDecimal(),
|
|
|
|
token.decimals
|
|
|
|
)
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenserTransaction.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleOwnerWinthdraw(event: OwnerWithdrawed): void {
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenserID = getDispenserGraphID(event.address, event.params.datatoken)
|
|
|
|
const dispenser = getDispenser(dispenserID)
|
2021-11-19 15:42:17 +01:00
|
|
|
dispenser.balance = decimal.ZERO
|
2023-05-13 14:00:52 +02:00
|
|
|
dispenser.eventIndex = event.logIndex.toI32()
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.save()
|
|
|
|
}
|