ocean-subgraph/src/mappings/erc721Factory.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-11-04 16:00:43 +01:00
import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
import { Nft, Token } from '../@types/schema'
2021-11-15 13:04:26 +01:00
import { decimal } from './utils/constants'
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())
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()
nft.name = event.params.tokenName.toHex()
nft.symbol = ''
2021-11-10 13:47:44 +01:00
nft.createdTimestamp = event.block.timestamp.toI32()
2021-11-04 16:00:43 +01:00
nft.tx = event.transaction.hash
nft.block = event.block.number.toI32()
nft.save()
}
export function handleNewToken(event: TokenCreated): void {
const token = new Token(event.params.newTokenAddress.toHexString())
token.isDatatoken = true
token.address = event.params.newTokenAddress.toHexString()
2021-11-10 13:47:44 +01:00
token.createdTimestamp = event.block.timestamp.toI32()
2021-11-04 16:00:43 +01:00
token.tx = event.transaction.hash
token.block = event.block.number.toI32()
token.name = event.params.tokenName.toString()
token.decimals = 18
2021-11-15 13:04:26 +01:00
token.supply = decimal.ZERO_BD
2021-11-04 16:00:43 +01:00
token.save()
}