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'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
dispenser.allowedSwapper = event.params.allowedSwapper.toHex()
|
|
|
|
dispenser.createdTimestamp = event.block.timestamp.toI32()
|
|
|
|
dispenser.tx = event.transaction.hash.toHex()
|
|
|
|
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
|
|
|
|
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)
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.active = true
|
|
|
|
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()
|
|
|
|
dispenser.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleTokensDispensed(event: TokensDispensed): void {
|
2022-02-20 09:00:16 +01:00
|
|
|
const dispenserID = getDispenserGraphID(
|
|
|
|
event.address,
|
|
|
|
event.params.datatokenAddress
|
|
|
|
)
|
2021-11-10 13:47:44 +01:00
|
|
|
const id = event.transaction.hash
|
|
|
|
.toHexString()
|
|
|
|
.concat('-')
|
2022-02-20 09:00:16 +01:00
|
|
|
.concat(dispenserID)
|
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()
|
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
|
2021-11-10 13:47:44 +01:00
|
|
|
dispenser.save()
|
|
|
|
}
|