2020-12-11 11:37:09 +01:00
|
|
|
import { BigInt, BigDecimal, log } from '@graphprotocol/graph-ts'
|
2021-02-09 11:13:31 +01:00
|
|
|
import { BPoolRegistered } from '../@types/Factory/Factory'
|
|
|
|
import { PoolFactory, Pool } from '../@types/schema'
|
|
|
|
import { Pool as PoolContract } from '../@types/templates'
|
2020-12-11 11:37:09 +01:00
|
|
|
import { ZERO_BD } from '../helpers'
|
2020-11-20 13:12:02 +01:00
|
|
|
|
|
|
|
export function handleNewPool(event: BPoolRegistered): void {
|
2020-12-02 11:07:09 +01:00
|
|
|
let factory = PoolFactory.load('1')
|
2020-11-20 13:12:02 +01:00
|
|
|
|
2021-01-19 12:16:03 +01:00
|
|
|
if (factory == null) {
|
2020-12-02 11:07:09 +01:00
|
|
|
factory = new PoolFactory('1')
|
2021-02-09 11:13:31 +01:00
|
|
|
factory.totalOceanLiquidity = ZERO_BD
|
2020-11-20 13:12:02 +01:00
|
|
|
factory.totalSwapVolume = ZERO_BD
|
|
|
|
factory.totalSwapFee = ZERO_BD
|
2021-02-09 11:13:31 +01:00
|
|
|
factory.totalValueLocked = ZERO_BD
|
2020-12-02 11:07:09 +01:00
|
|
|
|
|
|
|
factory.poolCount = 0
|
|
|
|
factory.finalizedPoolCount = 0
|
2020-11-20 13:12:02 +01:00
|
|
|
}
|
|
|
|
|
2020-12-11 11:37:09 +01:00
|
|
|
const pool = new Pool(event.params.bpoolAddress.toHexString())
|
|
|
|
log.info('************************ handleNewPool: poolId {}', [
|
|
|
|
pool.id.toString()
|
|
|
|
])
|
2020-12-02 11:07:09 +01:00
|
|
|
|
|
|
|
pool.factoryID = event.address.toHexString()
|
2020-11-20 13:12:02 +01:00
|
|
|
pool.controller = event.params.registeredBy
|
|
|
|
pool.publicSwap = false
|
|
|
|
pool.finalized = false
|
2020-12-02 11:07:09 +01:00
|
|
|
pool.symbol = ''
|
|
|
|
pool.name = ''
|
|
|
|
// pool.cap =
|
2020-11-20 13:12:02 +01:00
|
|
|
pool.active = true
|
|
|
|
pool.swapFee = BigDecimal.fromString('0.000001')
|
2020-12-02 11:07:09 +01:00
|
|
|
|
2020-11-20 13:12:02 +01:00
|
|
|
pool.totalWeight = ZERO_BD
|
|
|
|
pool.totalShares = ZERO_BD
|
|
|
|
pool.totalSwapVolume = ZERO_BD
|
|
|
|
pool.totalSwapFee = ZERO_BD
|
2021-02-09 11:13:31 +01:00
|
|
|
pool.valueLocked = ZERO_BD
|
2020-12-02 11:07:09 +01:00
|
|
|
|
|
|
|
pool.datatokenReserve = ZERO_BD
|
|
|
|
pool.oceanReserve = ZERO_BD
|
2020-12-11 11:37:09 +01:00
|
|
|
pool.spotPrice = ZERO_BD // : BigDecimal!
|
|
|
|
pool.consumePrice = ZERO_BD // : BigDecimal!
|
2020-12-02 11:07:09 +01:00
|
|
|
|
|
|
|
pool.tokenCount = BigInt.fromI32(0)
|
|
|
|
pool.holderCount = BigInt.fromI32(0)
|
|
|
|
pool.joinCount = BigInt.fromI32(0)
|
|
|
|
pool.exitCount = BigInt.fromI32(0)
|
|
|
|
pool.swapCount = BigInt.fromI32(0)
|
2020-12-09 11:54:13 +01:00
|
|
|
pool.transactionCount = BigInt.fromI32(0)
|
2020-12-02 11:07:09 +01:00
|
|
|
|
|
|
|
pool.datatokenAddress = ''
|
|
|
|
|
2020-11-20 13:12:02 +01:00
|
|
|
pool.createTime = event.block.timestamp.toI32()
|
|
|
|
pool.tx = event.transaction.hash
|
2020-12-02 11:07:09 +01:00
|
|
|
|
2020-11-20 13:12:02 +01:00
|
|
|
pool.save()
|
|
|
|
|
|
|
|
factory.poolCount = factory.poolCount + 1
|
|
|
|
factory.save()
|
|
|
|
|
|
|
|
PoolContract.create(event.params.bpoolAddress)
|
2020-12-11 11:37:09 +01:00
|
|
|
}
|