ocean-subgraph/src/mappings/poolFactory.ts

27 lines
897 B
TypeScript
Raw Normal View History

2021-11-12 14:22:35 +01:00
import { Pool } from '../@types/schema'
2021-12-02 13:10:23 +01:00
import { BPoolCreated } from '../@types/templates/BFactory/BFactory'
2021-12-07 10:47:58 +01:00
import { integer } from './utils/constants'
import { getGlobalStats } from './utils/globalUtils'
2021-12-02 12:08:47 +01:00
import { getToken } from './utils/tokenUtils'
2021-11-12 14:22:35 +01:00
export function handleNewPool(event: BPoolCreated): void {
const pool = new Pool(event.params.newBPoolAddress.toHex())
2021-12-02 12:08:47 +01:00
const baseToken = getToken(event.params.basetokenAddress.toHex())
2021-11-12 14:22:35 +01:00
pool.baseToken = baseToken.id
2021-12-02 12:08:47 +01:00
const datatoken = getToken(event.params.datatokenAddress.toHex())
2021-11-12 14:22:35 +01:00
pool.datatoken = datatoken.id
pool.owner = event.params.registeredBy.toHex()
2021-11-15 13:04:26 +01:00
2021-11-12 14:22:35 +01:00
pool.createdTimestamp = event.block.timestamp.toI32()
2021-12-02 12:08:47 +01:00
pool.tx = event.transaction.hash.toHex()
2021-11-12 14:22:35 +01:00
pool.block = event.block.number.toI32()
2021-12-07 10:47:58 +01:00
const globalStats = getGlobalStats()
globalStats.poolCount = globalStats.poolCount + 1
globalStats.save()
2021-11-12 14:22:35 +01:00
pool.save()
}