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
"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"
orderCount: BigInt
orderCount: BigInt!
"block time datatoken was created"
createdTimestamp: Int
createdTimestamp: Int!
"datatoken creation transaction id"
tx: String!
"block number when it was created"
block: Int
block: Int!
}
"utility type"
@ -194,7 +194,7 @@ type PoolTransaction @entity {
pool: Pool!
"user that initiates the tx"
user: User!
type: PoolTransactionType
type: PoolTransactionType!
"number of shares transfered"
sharesTransferAmount: BigDecimal

View File

@ -1,7 +1,7 @@
import { OrderStarted } from '../@types/ERC20Template/ERC20Template'
import { Order } from '../@types/schema'
import {
ConsumeMarketFees,
OrderStarted,
PublishMarketFees
} from '../@types/templates/ERC20Template/ERC20Template'
import { integer } from './utils/constants'
@ -9,7 +9,11 @@ import { weiToDecimal } from './utils/generic'
import { getToken } from './utils/tokenUtils'
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}`
}
@ -37,7 +41,7 @@ export function handleOrderStarted(event: OrderStarted): void {
token.decimals
)
order.serviceId = event.params.serviceId
order.serviceId = event.params.serviceId.toI32()
const publishMarket = getUser(event.params.publishMarketAddress.toHex())
order.publishingMarket = publishMarket.id
@ -53,26 +57,26 @@ export function handleOrderStarted(event: OrderStarted): void {
token.save()
}
export function handlePublishMarketFees(event: PublishMarketFees): void {
const order = Order.load(
getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
)
)
// export function handlePublishMarketFees(event: PublishMarketFees): void {
// const order = Order.load(
// getOrderId(
// event.transaction.hash.toHex(),
// event.address.toHex(),
// event.transaction.from.toHex()
// )
// )
order.save()
}
// order.save()
// }
export function handleConsumeMarketFees(event: ConsumeMarketFees): void {
const order = Order.load(
getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
)
)
// export function handleConsumeMarketFees(event: ConsumeMarketFees): void {
// const order = Order.load(
// getOrderId(
// event.transaction.hash.toHex(),
// event.address.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.isFinalized = true
const poolTx = PoolTransaction.load(event.transaction.hash.toHex())
if (poolTx) {
poolTx.type = PoolTransactionType.SETUP
poolTx.save()
}
pool.save()
datatoken.save()
@ -211,17 +216,14 @@ export function handleBpt(event: LOG_BPT): void {
const decimalBpt = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18)
switch (poolTx.type) {
case PoolTransactionType.JOIN: {
// for some reason switch is broken so reverting to good old if
if (poolTx.type === PoolTransactionType.JOIN) {
poolShares.shares = poolShares.shares.plus(decimalBpt)
pool.totalShares.plus(decimalBpt)
break
}
case PoolTransactionType.EXIT: {
if (poolTx.type === PoolTransactionType.EXIT) {
poolShares.shares = poolShares.shares.minus(decimalBpt)
pool.totalShares.minus(decimalBpt)
break
}
}
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 { BPoolCreated } from '../@types/templates/BFactory/BFactory'
import { getToken } from './utils/tokenUtils'
export function handleNewPool(event: BPoolCreated): void {

View File

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

View File

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