Bug/fix non ocean pools (#75)

* fix non ocean pools

* fixed fre bugs

* fix lint
This commit is contained in:
Alex Coseru 2021-04-16 11:07:01 +03:00 committed by GitHub
parent c092e64835
commit 52e8fb1e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 24 deletions

View File

@ -169,13 +169,33 @@ export function updatePoolTransactionToken(
feeValue: BigDecimal
): void {
log.warning('WWWWWWWWWW ---- started update ptx with id {}', [poolTx])
log.warning('updatePoolTransactionToken({}, {} , {} , {} , {}}', [
poolTx,
poolTokenId,
amount.toString(),
balance.toString(),
feeValue.toString()
])
const ptx = PoolTransaction.load(poolTx)
const poolToken = PoolToken.load(poolTokenId)
const pool = PoolEntity.load(poolToken.poolId)
if (!ptx) {
log.error('Cannot load PoolTransaction {}', [poolTx])
return
}
if (!poolToken) {
log.error('Cannot load PoolToken {}', [poolTokenId])
return
}
if (!pool) {
log.error('Cannot load PoolEntity {}', [poolToken.poolId])
return
}
const ptxTokenValuesId = poolTx.concat('-').concat(poolToken.tokenAddress)
let ptxTokenValues = PoolTransactionTokenValues.load(ptxTokenValuesId)
if (ptxTokenValues == null) {
ptxTokenValues = new PoolTransactionTokenValues(ptxTokenValuesId)
log.warning('created PoolTransactionTokenValues for {}', [ptxTokenValuesId])
}
ptxTokenValues.txId = poolTx
ptxTokenValues.poolToken = poolTokenId
@ -193,7 +213,7 @@ export function updatePoolTransactionToken(
}
ptxTokenValues.save()
log.warning('ptxTokenValues {} saved', [ptxTokenValues.id])
if (ptxTokenValues.tokenAddress == OCEAN) {
const factory = PoolFactory.load('1')
factory.totalOceanLiquidity =
@ -225,8 +245,9 @@ export function updatePoolTransactionToken(
// ptxTokenValues.tokenReserve.toString(),
// poolToken.poolId
// ])
log.warning('saving ptx {} ', [ptx.id.toString()])
ptx.save()
log.warning('saving pool {} ', [pool.id.toString()])
pool.save()
}

View File

@ -1,4 +1,4 @@
import { BigInt, ethereum } from '@graphprotocol/graph-ts'
import { BigInt, ethereum, log } from '@graphprotocol/graph-ts'
import {
ExchangeCreated,
ExchangeActivated,
@ -23,6 +23,10 @@ export function handleExchangeCreated(event: ExchangeCreated): void {
fixedrateexchange.datatoken = event.params.dataToken.toHexString()
fixedrateexchange.baseToken = event.params.baseToken.toHexString()
fixedrateexchange.active = false
log.info('for new exchange {} for rate {}', [
event.params.exchangeId.toHexString(),
event.params.fixedRate.toString()
])
fixedrateexchange.rate = tokenToDecimal(
event.params.fixedRate.toBigDecimal(),
BigInt.fromI32(18).toI32()
@ -71,10 +75,20 @@ export function handleExchangeRateChanged(event: ExchangeRateChanged): void {
const fixedrateexchange = FixedRateExchange.load(
event.params.exchangeId.toHexString()
)
if (!fixedrateexchange) {
log.error('Cannot update unknown FRE {}', [
event.params.exchangeId.toHexString()
])
return
}
const freupdate = new FixedRateExchangeUpdate(id)
freupdate.exchangeId = fixedrateexchange.id
freupdate.oldRate = fixedrateexchange.rate
log.info('for new exchange {} for rate {}', [
id,
event.params.newRate.toString()
])
freupdate.newRate = tokenToDecimal(
event.params.newRate.toBigDecimal(),
BigInt.fromI32(18).toI32()

View File

@ -6,33 +6,34 @@ import { Datatoken, MetadataUpdate } from '../@types/schema'
export function handleMetadataEvent(
event: ethereum.Event,
dtAddress: string,
updatedBy: string
updatedBy: string,
created: boolean
): void {
const datatoken = Datatoken.load(dtAddress)
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()
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()
event.params.updatedBy.toHexString(),
false
)
}
@ -40,6 +41,7 @@ export function handleMetadataCreated(event: MetadataCreated): void {
handleMetadataEvent(
event,
event.params.dataToken.toHexString(),
event.params.createdBy.toHexString()
event.params.createdBy.toHexString(),
true
)
}

View File

@ -1,4 +1,4 @@
import { BigInt, Address, BigDecimal } from '@graphprotocol/graph-ts'
import { BigInt, Address, BigDecimal, log } from '@graphprotocol/graph-ts'
import {
LOG_CALL,
LOG_JOIN,
@ -66,6 +66,16 @@ export function handleSetPublicSwap(event: LOG_CALL): void {
export function handleFinalize(event: LOG_CALL): void {
const poolId = event.address.toHex()
const pool = Pool.load(poolId)
if (pool === null) {
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
@ -157,6 +167,10 @@ export function handleSetup(event: LOG_CALL): void {
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 != null) return