delete old

This commit is contained in:
mihaisc 2021-12-02 14:28:27 +02:00
parent f6a0a874a2
commit 736c5bb5db
6 changed files with 0 additions and 1127 deletions

View File

@ -1,188 +0,0 @@
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
import { OrderStarted, Transfer } from '../@types/templates/DataToken/DataToken'
import {
Datatoken,
Global,
PoolFactory,
TokenBalance,
TokenOrder,
User
} from '../@types/schema'
import {
tokenToDecimal,
updateTokenBalance,
ZERO_BD,
MINUS_1_BD,
saveTokenTransaction,
getGlobalStats
} from '../helpers'
/************************************
********** Pool Controls ***********
************************************/
export function handleTransfer(event: Transfer): void {
const tokenId = event.address.toHex()
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
const amount = tokenToDecimal(event.params.value.toBigDecimal(), 18)
const tokenShareFrom = event.params.from.toHex()
const tokenShareTo = event.params.to.toHex()
const tokenBalanceFromId = tokenId.concat('-').concat(tokenShareFrom)
const tokenBalanceToId = tokenId.concat('-').concat(tokenShareTo)
let tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
let tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
let oldBalanceFrom = BigDecimal.fromString('0.0')
let oldBalanceTo = BigDecimal.fromString('0.0')
const isMint = tokenShareFrom == ZERO_ADDRESS
const isBurn = tokenShareTo == ZERO_ADDRESS
const datatoken = Datatoken.load(tokenId)
if (!datatoken) return
if (isMint) {
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
datatoken.supply = datatoken.supply.plus(amount)
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
} else if (isBurn) {
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
oldBalanceFrom =
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
datatoken.supply = datatoken.supply.minus(amount)
updateTokenBalance(
tokenBalanceFromId,
tokenId,
tokenShareFrom,
amount.times(MINUS_1_BD)
)
} else {
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
oldBalanceFrom =
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
datatoken.supply = datatoken.supply.minus(amount)
updateTokenBalance(
tokenBalanceFromId,
tokenId,
tokenShareFrom,
amount.times(MINUS_1_BD)
)
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
datatoken.supply = datatoken.supply.plus(amount)
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
}
if (
tokenBalanceTo != null &&
tokenBalanceTo.balance.notEqual(ZERO_BD) &&
oldBalanceTo.equals(ZERO_BD)
) {
datatoken.holderCount += BigInt.fromI32(1)
}
if (
tokenBalanceFrom != null &&
tokenBalanceFrom.balance.equals(ZERO_BD) &&
oldBalanceFrom.notEqual(ZERO_BD)
) {
datatoken.holderCount -= BigInt.fromI32(1)
}
datatoken.save()
saveTokenTransaction(event, 'Transfer')
}
export function handleOrderStarted(event: OrderStarted): void {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
const tokenId = event.address.toHex()
const datatoken = Datatoken.load(tokenId)
if (!datatoken) return
const payer = event.params.payer.toHex()
// let feeCollector = event.params.mrktFeeCollector
// let marketFee = event.params.marketFee
const tx = event.transaction.hash
const orderId = tokenId
.concat('-')
.concat(payer)
.concat('-')
.concat(tx.toHexString())
let order = TokenOrder.load(orderId)
if (order == null) {
order = new TokenOrder(orderId)
}
if (!order) return
order.datatokenId = tokenId
order.amount = tokenToDecimal(event.params.amount.toBigDecimal(), 18)
order.consumer = event.params.consumer.toHex()
order.payer = payer
order.serviceId = event.params.serviceId.toI32()
order.timestamp = event.params.timestamp.toI32()
if (
event.params.mrktFeeCollector !== null &&
event.params.mrktFeeCollector.toHex() !== ZERO_ADDRESS
) {
order.marketFeeCollector = event.params.mrktFeeCollector.toHexString()
}
order.marketFee = tokenToDecimal(event.params.marketFee.toBigDecimal(), 18)
order.tx = tx
order.block = event.block.number.toI32()
order.save()
const orderVolume = datatoken.orderVolume
datatoken.orderVolume = orderVolume
? orderVolume.plus(order.amount)
: BigDecimal.fromString('0')
const orderCount = datatoken.orderCount
datatoken.orderCount = orderCount
? orderCount.plus(BigInt.fromI32(1))
: BigInt.fromI32(0)
datatoken.save()
saveTokenTransaction(event, 'OrderStarted')
let factory = PoolFactory.load('1')
if (factory == null) {
factory = new PoolFactory('1')
factory.totalOceanLiquidity = ZERO_BD
factory.totalSwapVolume = ZERO_BD
factory.totalSwapFee = ZERO_BD
factory.totalValueLocked = ZERO_BD
factory.orderCount = BigInt.fromI32(0)
factory.poolCount = 0
factory.finalizedPoolCount = 0
}
if (factory !== null) {
const orderCount = factory.orderCount
factory.orderCount = orderCount
? orderCount.plus(BigInt.fromI32(1))
: BigInt.fromI32(0)
const totalOrderValue = factory.totalOrderVolume
factory.totalOrderVolume = totalOrderValue
? totalOrderValue.plus(order.amount)
: BigDecimal.fromString('0')
factory.save()
}
const user = User.load(datatoken.minter)
if (user !== null) {
user.nrSales = user.nrSales + 1
user.save()
}
const gStats: Global = getGlobalStats()
if (gStats !== null) {
gStats.orderCount = factory.orderCount
gStats.totalOrderVolume = factory.totalOrderVolume
gStats.save()
}
}

View File

@ -1,166 +0,0 @@
import { Address, BigInt, ethereum, log } from '@graphprotocol/graph-ts'
import {
Activated,
Deactivated,
AcceptedMinter,
RemovedMinter,
TokensDispensed,
OwnerWithdrawed,
Dispenser as DispenserEntity
} from '../@types/Dispenser/Dispenser'
import {
Dispenser,
DispenserTransaction,
User,
Datatoken
} from '../../@types/schema'
import { tokenToDecimal } from '../../helpers'
function _processDispenserUpdate(
event: ethereum.Event,
datatoken: string,
contractAddress: Address
): void {
const dt = Datatoken.load(datatoken)
if (!dt) {
return
}
let dispenser = Dispenser.load(datatoken)
if (!dispenser) {
dispenser = new Dispenser(datatoken)
}
const dispenserEntity = DispenserEntity.bind(contractAddress)
const dispenserStatus = dispenserEntity.try_status(
Address.fromString(datatoken)
)
if (dispenserStatus.reverted) return
dispenser.active = dispenserStatus.value.value0
let owner = User.load(dispenserStatus.value.value1.toHexString())
if (!owner) {
owner = new User(dispenserStatus.value.value1.toHexString())
owner.save()
}
dispenser.owner = owner.id
dispenser.minterApproved = dispenserStatus.value.value2
dispenser.isTrueMinter = dispenserStatus.value.value3
dispenser.maxTokens = tokenToDecimal(
dispenserStatus.value.value4.toBigDecimal(),
18
)
dispenser.maxBalance = tokenToDecimal(
dispenserStatus.value.value5.toBigDecimal(),
18
)
dispenser.balance = tokenToDecimal(
dispenserStatus.value.value6.toBigDecimal(),
18
)
dispenser.datatoken = dt.id
dispenser.save()
}
export function handleDispenserActivated(event: Activated): void {
_processDispenserUpdate(
event,
event.params.datatokenAddress.toHexString(),
event.address
)
}
export function handleDispenserDeactivated(event: Deactivated): void {
_processDispenserUpdate(
event,
event.params.datatokenAddress.toHexString(),
event.address
)
}
export function handleDispenserAcceptedMinter(event: AcceptedMinter): void {
_processDispenserUpdate(
event,
event.params.datatokenAddress.toHexString(),
event.address
)
}
export function handleDispenserRemovedMinter(event: RemovedMinter): void {
_processDispenserUpdate(
event,
event.params.datatokenAddress.toHexString(),
event.address
)
}
export function handleDispenserTokensDispensed(event: TokensDispensed): void {
_processDispenserUpdate(
event,
event.params.datatokenAddress.toHexString(),
event.address
)
const dt = Datatoken.load(event.params.datatokenAddress.toHexString())
if (!dt) {
log.warning('Tokens dispensed, but no datatoken ? ', [
event.params.datatokenAddress.toHexString()
])
return
}
const tx = event.transaction.hash
const id = tx
.toHexString()
.concat('-')
.concat(event.params.datatokenAddress.toHexString())
log.info('Created dispenser in handleDispenserTokensDispensed with id {}', [
id
])
const dispensers = new DispenserTransaction(id)
dispensers.dispenserId = event.params.datatokenAddress.toHexString()
dispensers.datatoken = event.params.datatokenAddress.toHexString()
dispensers.user = event.params.userAddress.toHexString()
dispensers.amount = tokenToDecimal(
event.params.amount.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
dispensers.block = event.block.number.toI32()
dispensers.timestamp = event.block.timestamp.toI32()
dispensers.tx = tx
dispensers.type = 'dispense'
dispensers.save()
}
export function handleDispenserOwnerWithdrawed(event: OwnerWithdrawed): void {
_processDispenserUpdate(
event,
event.params.datatoken.toHexString(),
event.address
)
const dt = Datatoken.load(event.params.datatoken.toHexString())
if (!dt) {
log.warning('Tokens dispensed, but no datatoken ? ', [
event.params.datatoken.toHexString()
])
return
}
const tx = event.transaction.hash
const id = tx
.toHexString()
.concat('-')
.concat(event.params.datatoken.toHexString())
log.info('Created dispenser in handleDispenserOwnerWithdrawed with id {} ', [
id
])
const dispensers = new DispenserTransaction(id)
dispensers.dispenserId = event.params.datatoken.toHexString()
dispensers.datatoken = event.params.datatoken.toHexString()
dispensers.user = event.params.owner.toHexString()
dispensers.amount = tokenToDecimal(
event.params.amount.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
dispensers.block = event.block.number.toI32()
dispensers.timestamp = event.block.timestamp.toI32()
dispensers.tx = tx
dispensers.type = 'withdraw'
dispensers.save()
}

View File

@ -1,51 +0,0 @@
import { BigInt, log } from '@graphprotocol/graph-ts'
import { TokenRegistered } from '../@types/DTFactory/DTFactory'
import {
DatatokenFactory,
Datatoken as DatatokenEntity
} from '../@types/schema'
import { DataToken as DatatokenDataSource } from '../@types/templates'
import { createUserEntity, tokenToDecimal, ZERO_BD } from '../helpers'
export function handleNewToken(event: TokenRegistered): void {
let factory = DatatokenFactory.load('1')
// if no factory yet, set up blank initial
if (factory == null) {
factory = new DatatokenFactory('1')
factory.tokenCount = 0
}
const datatoken = new DatatokenEntity(event.params.tokenAddress.toHexString())
log.warning('************************ handleNewToken: datatokenId {}', [
datatoken.id.toString()
])
datatoken.factoryID = event.address.toHexString()
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)
datatoken.supply = ZERO_BD
createUserEntity(event.params.registeredBy.toHex())
datatoken.minter = event.params.registeredBy.toHex()
datatoken.publisher = event.params.registeredBy.toHex()
datatoken.holderCount = BigInt.fromI32(0)
datatoken.orderCount = BigInt.fromI32(0)
datatoken.orderVolume = BigInt.fromI32(0).toBigDecimal()
datatoken.metadataUpdateCount = BigInt.fromI32(0)
datatoken.createTime = event.block.timestamp.toI32()
datatoken.tx = event.transaction.hash
datatoken.save()
factory.tokenCount = factory.tokenCount + 1
factory.save()
DatatokenDataSource.create(event.params.tokenAddress)
}

View File

@ -1,71 +0,0 @@
import { BigInt, BigDecimal, log } from '@graphprotocol/graph-ts'
import { BPoolRegistered } from '../@types/Factory/Factory'
import { PoolFactory, Pool, Global } from '../@types/schema'
import { Pool as PoolContract } from '../@types/templates'
import { ZERO_BD, getGlobalStats } from '../helpers'
export function handleNewPool(event: BPoolRegistered): void {
let factory = PoolFactory.load('1')
if (factory == null) {
factory = new PoolFactory('1')
factory.totalOceanLiquidity = ZERO_BD
factory.totalSwapVolume = ZERO_BD
factory.totalSwapFee = ZERO_BD
factory.totalValueLocked = ZERO_BD
factory.orderCount = BigInt.fromI32(0)
factory.poolCount = 0
factory.finalizedPoolCount = 0
}
const pool = new Pool(event.params.bpoolAddress.toHexString())
log.info('************************ handleNewPool: poolId {}', [
pool.id.toString()
])
pool.factoryID = event.address.toHexString()
pool.controller = event.params.registeredBy
pool.publicSwap = false
pool.finalized = false
pool.symbol = ''
pool.name = ''
// pool.cap =
pool.active = true
pool.swapFee = BigDecimal.fromString('0.000001')
pool.totalWeight = ZERO_BD
pool.totalShares = ZERO_BD
pool.totalSwapVolume = ZERO_BD
pool.totalSwapFee = ZERO_BD
pool.valueLocked = ZERO_BD
pool.datatokenReserve = ZERO_BD
pool.oceanReserve = ZERO_BD
pool.spotPrice = ZERO_BD // : BigDecimal!
pool.consumePrice = ZERO_BD // : BigDecimal!
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)
pool.transactionCount = BigInt.fromI32(0)
pool.datatokenAddress = ''
pool.createTime = event.block.timestamp.toI32()
pool.tx = event.transaction.hash
pool.save()
factory.poolCount = factory.poolCount + 1
factory.save()
const gStats: Global | null = getGlobalStats()
if (gStats) {
gStats.poolCount = factory.poolCount
gStats.save()
}
PoolContract.create(event.params.bpoolAddress)
}

View File

@ -1,74 +0,0 @@
import {
json,
BigInt,
ethereum,
log,
Bytes,
JSONValue,
JSONValueKind
} from '@graphprotocol/graph-ts'
import { MetadataUpdated, MetadataCreated } from '../@types/Metadata/Metadata'
import { Datatoken, MetadataUpdate } from '../@types/schema'
import { LZMA } from '../lzma/lzma'
export function handleMetadataEvent(
event: ethereum.Event,
dtAddress: string,
updatedBy: string,
created: boolean
): void {
const datatoken = Datatoken.load(dtAddress)
if (datatoken) {
const tx = event.transaction.hash
const id = tx.toHexString().concat('-').concat(dtAddress)
const metadataUpdate = new MetadataUpdate(id)
metadataUpdate.tx = tx
metadataUpdate.block = event.block.number.toI32()
metadataUpdate.timestamp = event.block.timestamp.toI32()
metadataUpdate.datatokenAddress = dtAddress
metadataUpdate.userAddress = updatedBy
metadataUpdate.datatokenId = dtAddress
metadataUpdate.save()
datatoken.metadataUpdateCount = datatoken.metadataUpdateCount.plus(
BigInt.fromI32(1)
)
datatoken.save()
}
}
export function handleMetadataUpdated(event: MetadataUpdated): void {
handleMetadataEvent(
event,
event.params.dataToken.toHexString(),
event.params.updatedBy.toHexString(),
false
)
}
export function jsonToString(val: JSONValue | null): string {
if (val != null && val.kind === JSONValueKind.STRING) {
return val.toString()
}
return ''
}
export function handleMetadataCreated(event: MetadataCreated): void {
const lzma = new LZMA()
const data = lzma.decode(event.params.data)
const obj = json.fromBytes(data.data as Bytes).toObject()
const did = obj.get('id')
const name = obj.get('service.attributes.main.name')
log.info('!!!!!!!!!!!!!!!!!!!!! DECOMPRESSED DATA {} {} {}', [
name.toString(),
did.toString(),
(data.data as Bytes).toString()
])
handleMetadataEvent(
event,
event.params.dataToken.toHexString(),
event.params.createdBy.toHexString(),
true
)
}

View File

@ -1,577 +0,0 @@
// import { BigInt, Address, BigDecimal, log } from '@graphprotocol/graph-ts'
// import {
// LOG_CALL,
// LOG_JOIN,
// LOG_EXIT,
// LOG_SWAP,
// Transfer,
// Pool as PoolEntity
// } from '../@types/templates/Pool/Pool'
// import {
// PoolFactory,
// Pool,
// PoolToken,
// PoolShare,
// Datatoken,
// PoolTransaction,
// Global
// } from '../@types/schema'
// import {
// hexToDecimal,
// tokenToDecimal,
// createPoolShareEntity,
// createPoolTokenEntity,
// ZERO_BD,
// MINUS_1_BD,
// decrPoolCount,
// updatePoolTransactionToken,
// createPoolTransaction,
// OCEAN,
// updatePoolTokenBalance,
// getOceanAddress,
// getGlobalStats,
// bigIntToDecimal
// } from '../helpers'
// /************************************
// ********** Pool Controls ***********
// ************************************/
// export function handleSetSwapFee(
// event: LOG_CALL,
// swapFeeStr: string | null = null
// ): void {
// const poolId = event.address.toHex()
// const pool = Pool.load(poolId)
// if (!pool) return
// if (!swapFeeStr) {
// swapFeeStr = event.params.data.toHexString().slice(-40)
// }
// if (swapFeeStr !== null) pool.swapFee = hexToDecimal(swapFeeStr, 18)
// pool.save()
// }
// export function handleSetController(event: LOG_CALL): void {
// const poolId = event.address.toHex()
// const pool = Pool.load(poolId)
// if (!pool) return
// pool.controller = Address.fromString(
// event.params.data.toHexString().slice(-40)
// )
// pool.save()
// }
// export function handleSetPublicSwap(event: LOG_CALL): void {
// const poolId = event.address.toHex()
// const pool = Pool.load(poolId)
// if (!pool) return
// pool.publicSwap = event.params.data.toHexString().slice(-1) == '1'
// pool.save()
// }
// export function handleFinalize(event: LOG_CALL): void {
// const poolId = event.address.toHex()
// const pool = Pool.load(poolId)
// if (!pool) {
// log.error('Cannot handle finalize for unknown pool {} ', [poolId])
// return
// }
// if (pool.tokenCount == BigInt.fromI32(0)) {
// log.error('Cannot mark pool {} finalized, because we have 0 tokenCount', [
// poolId
// ])
// return
// }
// pool.finalized = true
// pool.symbol = 'BPT'
// pool.publicSwap = true
// pool.save()
// const factory = PoolFactory.load('1')
// if (!factory) return
// factory.finalizedPoolCount = factory.finalizedPoolCount + 1
// factory.save()
// }
// export function _handleRebind(
// event: LOG_CALL,
// poolId: string,
// tokenAddress: string,
// balanceStr: string,
// denormWeightStr: string
// ): void {
// const pool = Pool.load(poolId)
// if (!pool) return
// const decimals = BigInt.fromI32(18).toI32()
// if (tokenAddress != OCEAN) {
// pool.datatokenAddress = tokenAddress
// }
// pool.tokenCount = pool.tokenCount.plus(BigInt.fromI32(1))
// const address = Address.fromString(tokenAddress)
// const denormWeight = hexToDecimal(denormWeightStr, decimals)
// const poolTokenId = poolId.concat('-').concat(address.toHexString())
// let poolToken = PoolToken.load(poolTokenId)
// if (poolToken == null) {
// createPoolTokenEntity(poolTokenId, poolId, address)
// poolToken = PoolToken.load(poolTokenId)
// pool.totalWeight = pool.totalWeight.plus(denormWeight)
// } else {
// const oldWeight = poolToken.denormWeight
// if (denormWeight > oldWeight) {
// pool.totalWeight = pool.totalWeight.plus(denormWeight).minus(oldWeight)
// } else {
// pool.totalWeight = pool.totalWeight.minus(oldWeight).minus(denormWeight)
// }
// }
// if (!poolToken) return
// poolToken.denormWeight =
// denormWeight !== null ? denormWeight : BigDecimal.fromString('0')
// const balance = hexToDecimal(balanceStr, decimals)
// updatePoolTokenBalance(poolToken as PoolToken, balance, '_handleRebind')
// poolToken.save()
// if (balance.equals(ZERO_BD)) {
// decrPoolCount(pool.finalized)
// pool.active = false
// }
// pool.save()
// }
// export function handleRebind(event: LOG_CALL): void {
// const poolId = event.address.toHex()
// _handleRebind(
// event,
// poolId,
// event.params.data.toHexString().slice(34, 74),
// event.params.data.toHexString().slice(74, 138),
// event.params.data.toHexString().slice(138)
// )
// }
// export function handleSetup(event: LOG_CALL): void {
// if (PoolTransaction.load(event.transaction.hash.toHexString()) != null) {
// return
// }
// const poolId = event.address.toHex()
// const data = event.params.data.toHexString()
// // First 2 chars are 0x
// // Next there is 8 chars
// // Next starts the data each params occupies exactly 64 chars
// // Each value is padded with 0s to the left
// // For an Address, need to remove the leading 24 zeros, because the address itself is 40 chars
// // For numbers we donot need to remove the leading zeros because they have no effect being on the left of the number
// // skip 8 then take the last 40 (2 + 8 + 24 = 34) to (2 + 8 + 64 = 74)
// const dataTokenAddress = Address.fromString(data.slice(34, 74)).toHexString()
// const dataTokenAmount = data.slice(74, 138) // 74+64
// const dataTokenWeight = data.slice(138, 202) // (74+64,74+(2*64)
// const baseTokenAddress = Address.fromString(
// data.slice(202 + 24, 266)
// ).toHexString() // (74+(2*64)+24, 74+(3*64))
// const baseTokenAmount = data.slice(266, 330) // (74+(3*64),74+(4*64))
// const baseTokenWeight = data.slice(330, 394) // (74+(4*64),74+(5*64))
// const swapFee = data.slice(394) // (74+(5*64), END)
// if (baseTokenAddress != OCEAN) {
// log.error('baseTokenAddress is not Ocean, but is {}', [baseTokenAddress])
// return
// }
// const poolTokenId = poolId.concat('-').concat(baseTokenAddress)
// const poolToken = PoolToken.load(poolTokenId)
// if (!poolToken) return
// _handleRebind(
// event,
// poolId,
// dataTokenAddress,
// dataTokenAmount,
// dataTokenWeight
// )
// _handleRebind(
// event,
// poolId,
// baseTokenAddress,
// baseTokenAmount,
// baseTokenWeight
// )
// handleSetSwapFee(event, swapFee)
// handleFinalize(event)
// createPoolTransaction(event, 'setup', event.transaction.from.toHex())
// // update base token
// let amount = hexToDecimal(baseTokenAmount, 18)
// const poolTokenBalance = poolToken.balance
// const balance = poolTokenBalance
// ? poolTokenBalance
// : BigDecimal.fromString('0')
// updatePoolTransactionToken(
// event.transaction.hash.toHexString(),
// poolTokenId,
// amount,
// balance,
// ZERO_BD
// )
// // update the datatoken
// const poolDataToken = PoolToken.load(
// poolId.concat('-').concat(dataTokenAddress)
// )
// if (poolDataToken !== null) {
// amount = hexToDecimal(dataTokenAmount, 18)
// updatePoolTransactionToken(
// event.transaction.hash.toHexString(),
// poolId.concat('-').concat(dataTokenAddress),
// amount,
// poolDataToken.balance,
// ZERO_BD
// )
// }
// }
// /************************************
// ********** JOINS & EXITS ***********
// ************************************/
// export function handleJoinPool(event: LOG_JOIN): void {
// const poolId = event.address.toHex()
// const address = event.params.tokenIn.toHex()
// const ptx = event.transaction.hash.toHexString()
// const poolTokenId = poolId.concat('-').concat(address)
// const poolToken = PoolToken.load(poolTokenId)
// const pool = Pool.load(poolId)
// const datatoken = Datatoken.load(poolTokenId)
// const poolTx = PoolTransaction.load(ptx)
// if (poolTx !== null) return
// if (!pool || !poolToken || !datatoken) return
// if (pool.finalized == false) {
// return
// }
// pool.joinCount = pool.joinCount.plus(BigInt.fromI32(1))
// pool.save()
// const decimals =
// datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
// const tokenAmountIn = tokenToDecimal(
// event.params.tokenAmountIn.toBigDecimal(),
// decimals
// )
// updatePoolTokenBalance(
// poolToken as PoolToken,
// poolToken.balance.plus(tokenAmountIn),
// 'handleJoinPool'
// )
// poolToken.save()
// createPoolTransaction(event, 'join', event.params.caller.toHexString())
// updatePoolTransactionToken(
// event.transaction.hash.toHexString(),
// poolTokenId,
// tokenAmountIn,
// poolToken.balance,
// tokenAmountIn.times(pool.swapFee)
// )
// }
// export function handleExitPool(event: LOG_EXIT): void {
// const poolId = event.address.toHex()
// const address = event.params.tokenOut.toHex()
// const poolTokenId = poolId.concat('-').concat(address.toString())
// const pool = Pool.load(poolId)
// const poolToken = PoolToken.load(poolTokenId)
// const datatoken = Datatoken.load(poolTokenId)
// if (!poolToken || !pool || !datatoken) {
// return
// }
// const decimals =
// datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
// const tokenAmountOut = tokenToDecimal(
// event.params.tokenAmountOut.toBigDecimal(),
// decimals
// )
// const newAmount = poolToken.balance.minus(tokenAmountOut)
// updatePoolTokenBalance(poolToken as PoolToken, newAmount, 'handleExitPool')
// poolToken.save()
// pool.exitCount = pool.exitCount.plus(BigInt.fromI32(1))
// if (newAmount.equals(ZERO_BD)) {
// decrPoolCount(pool.finalized)
// pool.active = false
// }
// pool.save()
// createPoolTransaction(event, 'exit', event.params.caller.toHexString())
// updatePoolTransactionToken(
// event.transaction.hash.toHexString(),
// poolTokenId,
// tokenAmountOut.times(MINUS_1_BD),
// poolToken.balance,
// tokenAmountOut.times(pool.swapFee)
// )
// }
// /************************************
// ************** SWAPS ***************
// ************************************/
// export function handleSwap(event: LOG_SWAP): void {
// const poolId = event.address.toHex()
// const ptx = event.transaction.hash.toHexString()
// const tokenIn = event.params.tokenIn.toHex()
// const poolTokenInId = poolId.concat('-').concat(tokenIn.toString())
// const poolTokenIn = PoolToken.load(poolTokenInId)
// if (!poolTokenIn) {
// return
// }
// const dtIn = Datatoken.load(tokenIn)
// const tokenAmountIn = tokenToDecimal(
// event.params.tokenAmountIn.toBigDecimal(),
// dtIn == null ? 18 : dtIn.decimals
// )
// const newAmountIn = poolTokenIn.balance.plus(tokenAmountIn)
// updatePoolTokenBalance(
// poolTokenIn as PoolToken,
// newAmountIn,
// 'handleSwap.tokenIn'
// )
// poolTokenIn.save()
// const tokenOut = event.params.tokenOut.toHex()
// const poolTokenOutId = poolId.concat('-').concat(tokenOut.toString())
// const poolTokenOut = PoolToken.load(poolTokenOutId)
// const pool = Pool.load(poolId)
// const factory = PoolFactory.load('1')
// const dtOut = Datatoken.load(tokenOut)
// if (!poolTokenOut || !dtOut || !factory || !pool) return
// const tokenAmountOut = tokenToDecimal(
// event.params.tokenAmountOut.toBigDecimal(),
// dtOut == null ? 18 : dtOut.decimals
// )
// const newAmountOut = poolTokenOut.balance.minus(tokenAmountOut)
// updatePoolTokenBalance(
// poolTokenOut as PoolToken,
// newAmountOut,
// 'handleSwap.tokenOut'
// )
// poolTokenOut.save()
// pool.swapCount = pool.swapCount.plus(BigInt.fromI32(1))
// if (newAmountIn.equals(ZERO_BD) || newAmountOut.equals(ZERO_BD)) {
// decrPoolCount(pool.finalized)
// pool.active = false
// }
// if (tokenIn === getOceanAddress()) {
// pool.totalSwapVolume = pool.totalSwapVolume.plus(tokenAmountIn)
// factory.totalSwapVolume = factory.totalSwapVolume.plus(tokenAmountIn)
// } else {
// pool.totalSwapVolume = pool.totalSwapVolume.plus(tokenAmountOut)
// factory.totalSwapVolume = factory.totalSwapVolume.plus(tokenAmountOut)
// }
// factory.save()
// pool.save()
// const gStats: Global = getGlobalStats()
// if (gStats !== null) {
// gStats.totalSwapVolume = factory.totalSwapVolume
// gStats.save()
// }
// createPoolTransaction(event, 'swap', event.params.caller.toHexString())
// updatePoolTransactionToken(
// ptx,
// poolTokenIn.id,
// tokenAmountIn,
// poolTokenIn.balance,
// tokenAmountIn.times(pool.swapFee)
// )
// updatePoolTransactionToken(
// ptx,
// poolTokenOut.id,
// tokenAmountOut.times(MINUS_1_BD),
// poolTokenOut.balance,
// BigDecimal.fromString('0.0')
// )
// }
// /************************************
// *********** POOL SHARES ************
// ************************************/
// export function handleTransfer(event: Transfer): void {
// const poolId = event.address.toHex()
// const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
// const isMint = event.params.from.toHex() == ZERO_ADDRESS
// const isBurn = event.params.to.toHex() == ZERO_ADDRESS
// const poolShareFromId = poolId.concat('-').concat(event.params.from.toHex())
// let poolShareFrom = PoolShare.load(poolShareFromId)
// const poolShareToId = poolId.concat('-').concat(event.params.to.toHex())
// let poolShareTo = PoolShare.load(poolShareToId)
// const poolShareToBalance = poolShareTo == null ? ZERO_BD : poolShareTo.balance
// const pool = Pool.load(poolId)
// if (!pool) return
// const poolTx = PoolTransaction.load(event.transaction.hash.toHexString())
// const value = tokenToDecimal(event.params.value.toBigDecimal(), 18)
// if (isMint) {
// if (poolShareTo == null) {
// createPoolShareEntity(poolShareToId, poolId, event.params.to.toHex())
// poolShareTo = PoolShare.load(poolShareToId)
// }
// if (poolShareTo !== null) {
// poolShareTo.balance = poolShareTo.balance.plus(value)
// poolShareTo.save()
// }
// pool.totalShares = pool.totalShares.plus(value)
// if (poolTx != null) {
// poolTx.sharesTransferAmount = value
// if (poolShareTo !== null) poolTx.sharesBalance = poolShareTo.balance
// }
// } else if (isBurn) {
// if (poolShareFrom == null) {
// createPoolShareEntity(poolShareFromId, poolId, event.params.from.toHex())
// poolShareFrom = PoolShare.load(poolShareFromId)
// }
// pool.totalShares = pool.totalShares.minus(value)
// if (poolTx !== null) {
// poolTx.sharesTransferAmount = poolTx.sharesTransferAmount.minus(value)
// }
// if (poolTx !== null && poolShareFrom !== null) {
// poolTx.sharesBalance = poolShareFrom.balance
// }
// if (poolShareFrom !== null) {
// poolShareFrom.balance = poolShareFrom.balance.minus(value)
// poolShareFrom.save()
// }
// } else {
// if (poolShareTo == null) {
// createPoolShareEntity(poolShareToId, poolId, event.params.to.toHex())
// poolShareTo = PoolShare.load(poolShareToId)
// }
// if (poolShareTo !== null) {
// poolShareTo.balance = poolShareTo.balance.plus(value)
// poolShareTo.save()
// }
// if (poolShareFrom == null) {
// createPoolShareEntity(poolShareFromId, poolId, event.params.from.toHex())
// poolShareFrom = PoolShare.load(poolShareFromId)
// }
// if (poolShareFrom !== null) {
// poolShareFrom.balance = poolShareFrom.balance.minus(value)
// poolShareFrom.save()
// }
// }
// if (
// poolShareTo != null &&
// poolShareTo.balance.notEqual(ZERO_BD) &&
// poolShareToBalance.equals(ZERO_BD)
// ) {
// pool.holderCount = pool.holderCount.plus(BigInt.fromI32(1))
// }
// if (
// poolShareFrom !== null &&
// poolShareFrom.balance.equals(ZERO_BD) &&
// poolShareFrom.balance.notEqual(ZERO_BD)
// ) {
// pool.holderCount = pool.holderCount.plus(BigInt.fromI32(1))
// }
// if (poolTx !== null) {
// poolTx.save()
// }
// pool.save()
// }
// /************************************
// *********** GULP ************
// ************************************/
// export function handleGulp(event: LOG_CALL): void {
// const poolId = event.address.toHex()
// const ptx = event.transaction.hash.toHexString()
// // we need to check the contract balance & compare with our internal balances
// const pool = Pool.load(poolId)
// const poolEbtity = PoolEntity.bind(Address.fromString(poolId))
// if (!pool) {
// log.warning('Gulp called, but cannot load pool {}', [poolId])
// return
// }
// const ocnToken = PoolToken.load(poolId.concat('-').concat(OCEAN))
// const dtToken = PoolToken.load(
// poolId.concat('-').concat(pool.datatokenAddress)
// )
// // get the balances from the contract
// // for ocean
// if (ocnToken) {
// const ocnTokenBalance = ocnToken.balance
// const balanceAttempt = poolEbtity.try_getBalance(Address.fromString(OCEAN))
// if (!balanceAttempt.reverted) {
// const contractBalance = bigIntToDecimal(balanceAttempt.value, 18)
// if (
// ocnToken.balance.notEqual(contractBalance) &&
// contractBalance.ge(ZERO_BD)
// ) {
// // we have a difference. let's absorb that
// createPoolTransaction(event, 'gulp', event.params.caller.toHexString())
// ocnToken.balance = contractBalance
// ocnToken.save()
// updatePoolTransactionToken(
// ptx,
// ocnToken.id,
// contractBalance.minus(ocnTokenBalance),
// contractBalance,
// ZERO_BD
// )
// }
// }
// }
// // for dt
// if (dtToken) {
// const dtTokenBalance = dtToken.balance
// const balanceAttempt = poolEbtity.try_getBalance(
// Address.fromString(pool.datatokenAddress)
// )
// if (!balanceAttempt.reverted) {
// const contractBalance = bigIntToDecimal(balanceAttempt.value, 18)
// if (
// dtToken.balance.notEqual(contractBalance) &&
// contractBalance.ge(ZERO_BD)
// ) {
// // we have a difference. let's absorb that
// createPoolTransaction(event, 'gulp', event.params.caller.toHexString())
// dtToken.balance = contractBalance
// dtToken.save()
// updatePoolTransactionToken(
// ptx,
// dtToken.id,
// contractBalance.minus(dtTokenBalance),
// contractBalance,
// ZERO_BD
// )
// }
// }
// }
// }