2020-12-11 11:37:09 +01:00
|
|
|
import { BigInt, log } from '@graphprotocol/graph-ts'
|
2020-11-26 07:38:08 +01:00
|
|
|
import { TokenRegistered } from '../types/DTFactory/DTFactory'
|
2020-12-08 13:32:15 +01:00
|
|
|
import { DatatokenFactory, Datatoken as DatatokenEntity } from '../types/schema'
|
|
|
|
import { DataToken as DatatokenDataSource } from '../types/templates'
|
|
|
|
|
2020-12-11 11:37:09 +01:00
|
|
|
import { createUserEntity, tokenToDecimal, ZERO_BD } from '../helpers'
|
2020-11-26 07:38:08 +01:00
|
|
|
|
|
|
|
export function handleNewToken(event: TokenRegistered): void {
|
2020-12-02 11:07:09 +01:00
|
|
|
let factory = DatatokenFactory.load('1')
|
2020-11-26 07:38:08 +01:00
|
|
|
|
|
|
|
// if no factory yet, set up blank initial
|
|
|
|
if (factory == null) {
|
2020-12-02 11:07:09 +01:00
|
|
|
factory = new DatatokenFactory('1')
|
2020-11-26 07:38:08 +01:00
|
|
|
factory.tokenCount = 0
|
|
|
|
}
|
|
|
|
|
2020-12-11 11:37:09 +01:00
|
|
|
const datatoken = new DatatokenEntity(event.params.tokenAddress.toHexString())
|
|
|
|
log.error('************************ handleNewToken: datatokenId {}', [
|
|
|
|
datatoken.id.toString()
|
|
|
|
])
|
2020-11-26 12:10:45 +01:00
|
|
|
|
|
|
|
datatoken.factoryID = event.address.toHexString()
|
2020-12-02 11:07:09 +01:00
|
|
|
|
2020-11-26 12:10:45 +01:00
|
|
|
datatoken.symbol = event.params.tokenSymbol
|
|
|
|
datatoken.name = event.params.tokenName
|
|
|
|
datatoken.decimals = 18
|
|
|
|
datatoken.address = event.params.tokenAddress.toHexString()
|
|
|
|
datatoken.cap = tokenToDecimal(event.params.tokenCap.toBigDecimal(), 18)
|
2020-11-26 07:38:08 +01:00
|
|
|
datatoken.supply = ZERO_BD
|
2020-12-02 11:26:50 +01:00
|
|
|
|
|
|
|
createUserEntity(event.params.registeredBy.toHex())
|
2020-11-26 12:10:45 +01:00
|
|
|
datatoken.minter = event.params.registeredBy.toHex()
|
|
|
|
datatoken.publisher = event.params.registeredBy.toHex()
|
2020-12-02 11:07:09 +01:00
|
|
|
|
|
|
|
datatoken.holderCount = BigInt.fromI32(0)
|
2020-11-26 12:10:45 +01:00
|
|
|
datatoken.orderCount = BigInt.fromI32(0)
|
2020-12-02 11:07:09 +01:00
|
|
|
|
|
|
|
datatoken.createTime = event.block.timestamp.toI32()
|
2020-11-26 07:38:08 +01:00
|
|
|
datatoken.tx = event.transaction.hash
|
|
|
|
datatoken.save()
|
|
|
|
|
|
|
|
factory.tokenCount = factory.tokenCount + 1
|
|
|
|
factory.save()
|
|
|
|
|
2020-12-08 13:32:15 +01:00
|
|
|
DatatokenDataSource.create(event.params.tokenAddress)
|
2020-12-11 11:37:09 +01:00
|
|
|
}
|