mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
add event Index to pool transactions (#497)
This commit is contained in:
parent
13d7fb78c1
commit
e7cb995797
@ -207,7 +207,7 @@ type PoolShare @entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PoolTransaction @entity {
|
type PoolTransaction @entity {
|
||||||
"tx address + caller address"
|
"tx address + eventIndex"
|
||||||
id: ID!
|
id: ID!
|
||||||
"pool related to this tx"
|
"pool related to this tx"
|
||||||
pool: Pool!
|
pool: Pool!
|
||||||
@ -222,6 +222,7 @@ type PoolTransaction @entity {
|
|||||||
timestamp: Int!
|
timestamp: Int!
|
||||||
"pool creation transaction id"
|
"pool creation transaction id"
|
||||||
tx: String!
|
tx: String!
|
||||||
|
eventIndex: BigInt
|
||||||
"block number when it was created"
|
"block number when it was created"
|
||||||
block: Int
|
block: Int
|
||||||
|
|
||||||
|
@ -32,7 +32,12 @@ import { getUser } from './utils/userUtils'
|
|||||||
export function handleJoin(event: LOG_JOIN): void {
|
export function handleJoin(event: LOG_JOIN): void {
|
||||||
const pool = getPool(event.address.toHex())
|
const pool = getPool(event.address.toHex())
|
||||||
const user = getUser(event.params.caller.toHex())
|
const user = getUser(event.params.caller.toHex())
|
||||||
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.JOIN)
|
const poolTx = getPoolTransaction(
|
||||||
|
event,
|
||||||
|
user.id,
|
||||||
|
PoolTransactionType.JOIN,
|
||||||
|
event.logIndex
|
||||||
|
)
|
||||||
|
|
||||||
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
||||||
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
||||||
@ -72,7 +77,12 @@ export function handleJoin(event: LOG_JOIN): void {
|
|||||||
export function handleExit(event: LOG_EXIT): void {
|
export function handleExit(event: LOG_EXIT): void {
|
||||||
const pool = getPool(event.address.toHex())
|
const pool = getPool(event.address.toHex())
|
||||||
const user = getUser(event.params.caller.toHex())
|
const user = getUser(event.params.caller.toHex())
|
||||||
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.EXIT)
|
const poolTx = getPoolTransaction(
|
||||||
|
event,
|
||||||
|
user.id,
|
||||||
|
PoolTransactionType.EXIT,
|
||||||
|
event.logIndex
|
||||||
|
)
|
||||||
|
|
||||||
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
||||||
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
||||||
@ -109,7 +119,12 @@ export function handleExit(event: LOG_EXIT): void {
|
|||||||
export function handleSwap(event: LOG_SWAP): void {
|
export function handleSwap(event: LOG_SWAP): void {
|
||||||
const pool = getPool(event.address.toHex())
|
const pool = getPool(event.address.toHex())
|
||||||
const user = getUser(event.params.caller.toHex())
|
const user = getUser(event.params.caller.toHex())
|
||||||
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.SWAP)
|
const poolTx = getPoolTransaction(
|
||||||
|
event,
|
||||||
|
user.id,
|
||||||
|
PoolTransactionType.SWAP,
|
||||||
|
event.logIndex
|
||||||
|
)
|
||||||
|
|
||||||
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
|
||||||
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
pool.joinCount = pool.joinCount.plus(integer.ONE)
|
||||||
@ -227,7 +242,8 @@ export function handleSetup(event: LOG_SETUP): void {
|
|||||||
const poolTx = getPoolTransaction(
|
const poolTx = getPoolTransaction(
|
||||||
event,
|
event,
|
||||||
fromUser.id,
|
fromUser.id,
|
||||||
PoolTransactionType.SETUP
|
PoolTransactionType.SETUP,
|
||||||
|
event.logIndex
|
||||||
)
|
)
|
||||||
poolTx.type = PoolTransactionType.SETUP
|
poolTx.type = PoolTransactionType.SETUP
|
||||||
poolTx.baseToken = token.id
|
poolTx.baseToken = token.id
|
||||||
@ -259,7 +275,12 @@ export function handlerBptTransfer(event: Transfer): void {
|
|||||||
const toAddress = event.params.dst.toHexString()
|
const toAddress = event.params.dst.toHexString()
|
||||||
const poolAddress = event.address.toHex()
|
const poolAddress = event.address.toHex()
|
||||||
const caller = getUser(event.transaction.from.toHex())
|
const caller = getUser(event.transaction.from.toHex())
|
||||||
const poolTx = getPoolTransaction(event, caller.id, PoolTransactionType.SWAP)
|
const poolTx = getPoolTransaction(
|
||||||
|
event,
|
||||||
|
caller.id,
|
||||||
|
PoolTransactionType.SWAP,
|
||||||
|
event.logIndex
|
||||||
|
)
|
||||||
|
|
||||||
// btoken has 18 decimals
|
// btoken has 18 decimals
|
||||||
const ammount = weiToDecimal(event.params.amt.toBigDecimal(), 18)
|
const ammount = weiToDecimal(event.params.amt.toBigDecimal(), 18)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Address, BigDecimal, ethereum } from '@graphprotocol/graph-ts'
|
import { Address, BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts'
|
||||||
import {
|
import {
|
||||||
Pool,
|
Pool,
|
||||||
PoolShare,
|
PoolShare,
|
||||||
@ -19,19 +19,20 @@ export function getPoolShareId(
|
|||||||
|
|
||||||
export function getPoolTransactionId(
|
export function getPoolTransactionId(
|
||||||
txHash: string,
|
txHash: string,
|
||||||
userAddress: string
|
eventIndex: BigInt
|
||||||
): string {
|
): string {
|
||||||
return `${txHash}-${userAddress}`
|
return `${txHash}-` + eventIndex.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPoolTransaction(
|
export function getPoolTransaction(
|
||||||
event: ethereum.Event,
|
event: ethereum.Event,
|
||||||
userAddress: string,
|
userAddress: string,
|
||||||
type: string
|
type: string,
|
||||||
|
eventIndex: BigInt
|
||||||
): PoolTransaction {
|
): PoolTransaction {
|
||||||
const txId = getPoolTransactionId(
|
const txId = getPoolTransactionId(
|
||||||
event.transaction.hash.toHexString(),
|
event.transaction.hash.toHexString(),
|
||||||
userAddress
|
eventIndex
|
||||||
)
|
)
|
||||||
let poolTx = PoolTransaction.load(txId)
|
let poolTx = PoolTransaction.load(txId)
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ export function getPoolTransaction(
|
|||||||
|
|
||||||
poolTx.timestamp = event.block.timestamp.toI32()
|
poolTx.timestamp = event.block.timestamp.toI32()
|
||||||
poolTx.tx = event.transaction.hash.toHex()
|
poolTx.tx = event.transaction.hash.toHex()
|
||||||
|
poolTx.eventIndex = eventIndex
|
||||||
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())
|
||||||
|
Loading…
Reference in New Issue
Block a user