fix build

This commit is contained in:
mihaisc 2021-12-02 14:10:23 +02:00
parent 89b494c765
commit f6a0a874a2
6 changed files with 63 additions and 56 deletions

View File

@ -30,19 +30,19 @@ type Token @entity {
templateId: Int templateId: Int
"number of addresses holding a balance of datatoken , TODO: can we actually calculate this? what happens when users trade the dts" "number of addresses holding a balance of datatoken , TODO: can we actually calculate this? what happens when users trade the dts"
holderCount: BigInt holderCount: BigInt!
"number of orders executed for this datatoken" "number of orders executed for this datatoken"
orderCount: BigInt orderCount: BigInt!
"block time datatoken was created" "block time datatoken was created"
createdTimestamp: Int createdTimestamp: Int!
"datatoken creation transaction id" "datatoken creation transaction id"
tx: String! tx: String!
"block number when it was created" "block number when it was created"
block: Int block: Int!
} }
"utility type" "utility type"
@ -194,7 +194,7 @@ type PoolTransaction @entity {
pool: Pool! pool: Pool!
"user that initiates the tx" "user that initiates the tx"
user: User! user: User!
type: PoolTransactionType type: PoolTransactionType!
"number of shares transfered" "number of shares transfered"
sharesTransferAmount: BigDecimal sharesTransferAmount: BigDecimal

View File

@ -1,7 +1,7 @@
import { OrderStarted } from '../@types/ERC20Template/ERC20Template'
import { Order } from '../@types/schema' import { Order } from '../@types/schema'
import { import {
ConsumeMarketFees, ConsumeMarketFees,
OrderStarted,
PublishMarketFees PublishMarketFees
} from '../@types/templates/ERC20Template/ERC20Template' } from '../@types/templates/ERC20Template/ERC20Template'
import { integer } from './utils/constants' import { integer } from './utils/constants'
@ -9,7 +9,11 @@ import { weiToDecimal } from './utils/generic'
import { getToken } from './utils/tokenUtils' import { getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils' import { getUser } from './utils/userUtils'
function getOrderId(tx: string, tokenAddress: string, fromAddress: string) { function getOrderId(
tx: string,
tokenAddress: string,
fromAddress: string
): string {
return `${tx}-${tokenAddress}-${fromAddress}` return `${tx}-${tokenAddress}-${fromAddress}`
} }
@ -37,7 +41,7 @@ export function handleOrderStarted(event: OrderStarted): void {
token.decimals token.decimals
) )
order.serviceId = event.params.serviceId order.serviceId = event.params.serviceId.toI32()
const publishMarket = getUser(event.params.publishMarketAddress.toHex()) const publishMarket = getUser(event.params.publishMarketAddress.toHex())
order.publishingMarket = publishMarket.id order.publishingMarket = publishMarket.id
@ -53,26 +57,26 @@ export function handleOrderStarted(event: OrderStarted): void {
token.save() token.save()
} }
export function handlePublishMarketFees(event: PublishMarketFees): void { // export function handlePublishMarketFees(event: PublishMarketFees): void {
const order = Order.load( // const order = Order.load(
getOrderId( // getOrderId(
event.transaction.hash.toHex(), // event.transaction.hash.toHex(),
event.address.toHex(), // event.address.toHex(),
event.transaction.from.toHex() // event.transaction.from.toHex()
) // )
) // )
order.save() // order.save()
} // }
export function handleConsumeMarketFees(event: ConsumeMarketFees): void { // export function handleConsumeMarketFees(event: ConsumeMarketFees): void {
const order = Order.load( // const order = Order.load(
getOrderId( // getOrderId(
event.transaction.hash.toHex(), // event.transaction.hash.toHex(),
event.address.toHex(), // event.address.toHex(),
event.transaction.from.toHex() // event.transaction.from.toHex()
) // )
) // )
order.save() // order.save()
} // }

View File

@ -197,6 +197,11 @@ export function handleSetup(event: LOG_SETUP): void {
) )
pool.spotPrice = spotPrice pool.spotPrice = spotPrice
pool.isFinalized = true pool.isFinalized = true
const poolTx = PoolTransaction.load(event.transaction.hash.toHex())
if (poolTx) {
poolTx.type = PoolTransactionType.SETUP
poolTx.save()
}
pool.save() pool.save()
datatoken.save() datatoken.save()
@ -211,17 +216,14 @@ export function handleBpt(event: LOG_BPT): void {
const decimalBpt = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18) const decimalBpt = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18)
switch (poolTx.type) { // for some reason switch is broken so reverting to good old if
case PoolTransactionType.JOIN: { if (poolTx.type === PoolTransactionType.JOIN) {
poolShares.shares = poolShares.shares.plus(decimalBpt) poolShares.shares = poolShares.shares.plus(decimalBpt)
pool.totalShares.plus(decimalBpt) pool.totalShares.plus(decimalBpt)
break }
} if (poolTx.type === PoolTransactionType.EXIT) {
case PoolTransactionType.EXIT: { poolShares.shares = poolShares.shares.minus(decimalBpt)
poolShares.shares = poolShares.shares.minus(decimalBpt) pool.totalShares.minus(decimalBpt)
pool.totalShares.minus(decimalBpt)
break
}
} }
poolShares.shares = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18) poolShares.shares = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18)

View File

@ -1,5 +1,5 @@
import { BPoolCreated } from '../@types/FactoryRouter/FactoryRouter'
import { Pool } from '../@types/schema' import { Pool } from '../@types/schema'
import { BPoolCreated } from '../@types/templates/BFactory/BFactory'
import { getToken } from './utils/tokenUtils' import { getToken } from './utils/tokenUtils'
export function handleNewPool(event: BPoolCreated): void { export function handleNewPool(event: BPoolCreated): void {

View File

@ -19,16 +19,17 @@ export namespace decimal {
export const BONE = BigDecimal.fromString('1000000000000000000') export const BONE = BigDecimal.fromString('1000000000000000000')
} }
export enum PoolTransactionType { // string enums don't work in wasm so this was the alternative, not optimal
JOIN = 'JOIN', export namespace PoolTransactionType {
EXIT = 'EXIT', export const JOIN = 'JOIN'
SWAP = 'SWAP', export const EXIT = 'EXIT'
SETUP = 'SETUP' export const SWAP = 'SWAP'
export const SETUP = 'SETUP'
} }
export enum NftUpdateType { export namespace NftUpdateType {
METADATA_CREATED = 'METADATA_CREATED', export const METADATA_CREATED = 'METADATA_CREATED'
METADATA_UPDATED = 'METADATA_UPDATED', export const METADATA_UPDATED = 'METADATA_UPDATED'
STATE_UPDATED = 'STATE_UPDATED', export const STATE_UPDATED = 'STATE_UPDATED'
TOKENURI_UPDATED = 'TOKENURI_UPDATED' export const TOKENURI_UPDATED = 'TOKENURI_UPDATED'
} }

View File

@ -19,7 +19,7 @@ export function getPoolSharesId(
export function getPoolTransaction( export function getPoolTransaction(
event: ethereum.Event, event: ethereum.Event,
userAddress: string, userAddress: string,
type: PoolTransactionType type: string
): PoolTransaction { ): PoolTransaction {
let poolTx = PoolTransaction.load(event.transaction.hash.toHex()) let poolTx = PoolTransaction.load(event.transaction.hash.toHex())
@ -32,7 +32,7 @@ export function getPoolTransaction(
poolTx.type = type poolTx.type = type
poolTx.timestamp = event.block.timestamp.toI32() poolTx.timestamp = event.block.timestamp.toI32()
poolTx.tx = event.transaction.hash poolTx.tx = event.transaction.hash.toHex()
poolTx.block = event.block.number.toI32() poolTx.block = event.block.number.toI32()
poolTx.gasPrice = gweiToEth(event.transaction.gasPrice.toBigDecimal()) poolTx.gasPrice = gweiToEth(event.transaction.gasPrice.toBigDecimal())
@ -73,8 +73,8 @@ export function calcSpotPrice(
const weiPrice = poolContract.try_getSpotPrice( const weiPrice = poolContract.try_getSpotPrice(
Address.fromString(baseTokenAddress), Address.fromString(baseTokenAddress),
Address.fromString(datatokenAddress) Address.fromString(datatokenAddress)
).reverted ).value
const price = weiToDecimal(weiPrice, baseTokenDecimals) const price = weiToDecimal(weiPrice.toBigDecimal(), baseTokenDecimals)
return price return price
} }
@ -93,7 +93,8 @@ export function createPoolSnapshot(
): PoolSnapshot { ): PoolSnapshot {
const snapshotId = getPoolSnapshotId(poolAddress, timestamp) const snapshotId = getPoolSnapshotId(poolAddress, timestamp)
const pool = Pool.load(poolAddress) const pool = getPool(poolAddress)
const snapshot = new PoolSnapshot(snapshotId) const snapshot = new PoolSnapshot(snapshotId)
snapshot.pool = poolAddress snapshot.pool = poolAddress
@ -102,7 +103,6 @@ export function createPoolSnapshot(
snapshot.swapVolume = decimal.ZERO snapshot.swapVolume = decimal.ZERO
snapshot.swapFees = decimal.ZERO snapshot.swapFees = decimal.ZERO
snapshot.baseToken = pool.baseToken snapshot.baseToken = pool.baseToken
//snapshot.baseTokenLiquidity = pool.baseToken
snapshot.datatoken = pool.datatoken snapshot.datatoken = pool.datatoken
snapshot.datatokenLiquidity = decimal.ZERO snapshot.datatokenLiquidity = decimal.ZERO