2021-11-04 16:00:43 +01:00
|
|
|
import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
|
|
|
|
import { Nft, Token } from '../@types/schema'
|
2022-01-14 15:51:23 +01:00
|
|
|
import { ERC20Template, ERC721Template } from '../@types/templates'
|
2021-12-07 10:47:58 +01:00
|
|
|
import { decimal, integer } from './utils/constants'
|
2022-01-13 17:24:57 +01:00
|
|
|
import { weiToDecimal } from './utils/generic'
|
2021-12-07 10:47:58 +01:00
|
|
|
import { getGlobalStats } from './utils/globalUtils'
|
2021-11-10 13:47:44 +01:00
|
|
|
import { getUser } from './utils/userUtils'
|
2021-11-04 16:00:43 +01:00
|
|
|
|
|
|
|
export function handleNftCreated(event: NFTCreated): void {
|
|
|
|
const nft = new Nft(event.params.newTokenAddress.toHexString())
|
2022-01-14 15:51:23 +01:00
|
|
|
ERC721Template.create(event.params.newTokenAddress)
|
2021-11-10 13:47:44 +01:00
|
|
|
const user = getUser(event.params.admin.toHexString())
|
|
|
|
nft.owner = user.id
|
2021-11-04 16:00:43 +01:00
|
|
|
nft.address = event.params.newTokenAddress.toHexString()
|
2021-11-19 15:42:17 +01:00
|
|
|
nft.name = event.params.tokenName
|
2021-11-04 16:00:43 +01:00
|
|
|
nft.symbol = ''
|
2021-11-10 13:47:44 +01:00
|
|
|
nft.createdTimestamp = event.block.timestamp.toI32()
|
2021-12-02 12:08:47 +01:00
|
|
|
nft.tx = event.transaction.hash.toHex()
|
2021-11-04 16:00:43 +01:00
|
|
|
nft.block = event.block.number.toI32()
|
|
|
|
|
2021-12-07 10:47:58 +01:00
|
|
|
const globalStats = getGlobalStats()
|
|
|
|
globalStats.nftCount = globalStats.nftCount.plus(integer.ONE)
|
|
|
|
|
|
|
|
globalStats.save()
|
2021-11-04 16:00:43 +01:00
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleNewToken(event: TokenCreated): void {
|
|
|
|
const token = new Token(event.params.newTokenAddress.toHexString())
|
2022-01-14 15:51:23 +01:00
|
|
|
ERC20Template.create(event.params.newTokenAddress)
|
2021-11-04 16:00:43 +01:00
|
|
|
token.isDatatoken = true
|
|
|
|
token.address = event.params.newTokenAddress.toHexString()
|
2021-11-10 13:47:44 +01:00
|
|
|
token.createdTimestamp = event.block.timestamp.toI32()
|
2021-12-02 12:08:47 +01:00
|
|
|
token.tx = event.transaction.hash.toHex()
|
2021-11-04 16:00:43 +01:00
|
|
|
token.block = event.block.number.toI32()
|
|
|
|
|
2022-01-13 17:24:57 +01:00
|
|
|
token.nft = event.params.creator.toHexString()
|
|
|
|
|
2021-11-19 15:42:17 +01:00
|
|
|
token.name = event.params.name
|
2022-01-13 17:24:57 +01:00
|
|
|
token.symbol = event.params.symbol
|
2021-11-04 16:00:43 +01:00
|
|
|
token.decimals = 18
|
2021-11-19 15:42:17 +01:00
|
|
|
token.supply = decimal.ZERO
|
2022-01-13 17:24:57 +01:00
|
|
|
token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18)
|
2021-12-07 10:47:58 +01:00
|
|
|
|
|
|
|
const globalStats = getGlobalStats()
|
|
|
|
globalStats.datatokenCount = globalStats.datatokenCount.plus(integer.ONE)
|
|
|
|
|
|
|
|
globalStats.save()
|
2021-11-04 16:00:43 +01:00
|
|
|
token.save()
|
|
|
|
}
|