diff --git a/src/mappings/erc721Factory.ts b/src/mappings/erc721Factory.ts index c1184bbf..5c87eaf9 100644 --- a/src/mappings/erc721Factory.ts +++ b/src/mappings/erc721Factory.ts @@ -15,11 +15,12 @@ import { getUser } from './utils/userUtils' import { getToken, getNftToken, - getPredictContract, - getErc20TemplateId + getErc20TemplateId, + getPredictContract } from './utils/tokenUtils' import { BigInt } from '@graphprotocol/graph-ts' import { addDatatoken } from './utils/globalUtils' + export function handleNftCreated(event: NFTCreated): void { // const nft = new Nft(event.params.newTokenAddress.toHexString()) const nft = getNftToken(event.params.newTokenAddress) @@ -37,7 +38,6 @@ export function handleNftCreated(event: NFTCreated): void { nft.eventIndex = event.logIndex.toI32() nft.transferable = event.params.transferable nft.template = event.params.templateAddress.toHexString() - nft.save() } @@ -62,7 +62,7 @@ export function handleNewToken(event: TokenCreated): void { token.templateId = getErc20TemplateId(event.params.templateAddress) token.save() addDatatoken() - if (token.templateId == BigInt.fromString('3')) { + if (token.templateId === BigInt.fromString('3')) { factoryERC20Template3.create(event.params.newTokenAddress) const predictContract = getPredictContract(event.params.newTokenAddress) predictContract.timestamp = event.block.timestamp.toI32() diff --git a/src/mappings/utils/tokenUtils.ts b/src/mappings/utils/tokenUtils.ts index 0500f0ae..89fdbc7e 100644 --- a/src/mappings/utils/tokenUtils.ts +++ b/src/mappings/utils/tokenUtils.ts @@ -114,6 +114,22 @@ export function getUSDValue( return BigDecimal.zero() } +export function getErc721TemplateId(address: Address): BigInt { + const template = Erc721Template.load(address.toHexString()) + if (template) { + return template.templateId + } + return BigInt.zero() +} + +export function getErc20TemplateId(address: Address): BigInt { + const template = Erc20Template.load(address.toHexString()) + if (template) { + return template.templateId + } + return BigInt.zero() +} + export function createPredictContract(address: Address): PredictContract { const predictContract = new PredictContract(address.toHexString()) const token = getToken(address, true) @@ -137,19 +153,3 @@ export function getPredictContract(address: Address): PredictContract { } return newPredictContract } - -export function getErc721TemplateId(address: Address): BigInt { - const template = Erc721Template.load(address.toHexString()) - if (template) { - return template.templateId - } - return BigInt.zero() -} - -export function getErc20TemplateId(address: Address): BigInt { - const template = Erc20Template.load(address.toHexString()) - if (template) { - return template.templateId - } - return BigInt.zero() -}