Add gasUsed and gasPrice to order (#540)

* Add gasused to order



Co-authored-by: alexcos20 <alex.coseru@gmail.com>
This commit is contained in:
Berkay Saglam 2022-09-20 23:47:09 +03:00 committed by GitHub
parent d2ddf2d156
commit f61cce9722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -134,6 +134,8 @@ type OrderReuse @entity {
block: Int!
providerFee: String
providerFeeValidUntil: BigInt
gasPrice: BigInt
gasUsed: BigInt
}
type Order @entity {
@ -167,6 +169,8 @@ type Order @entity {
lastPriceToken: String!
lastPriceValue: BigDecimal!
estimatedUSDValue: BigDecimal!
gasUsed: BigInt
gasPrice: BigInt
}
type User @entity {

View File

@ -1,5 +1,6 @@
import { Order, Nft, OrderReuse } from '../@types/schema'
import { BigInt } from '@graphprotocol/graph-ts'
import {
NewPaymentCollector,
OrderStarted,
@ -65,6 +66,16 @@ export function handleOrderStarted(event: OrderStarted): void {
order.lastPriceValue,
order.createdTimestamp
)
if (event.receipt !== null) {
order.gasUsed = event.receipt!.gasUsed
} else {
order.gasUsed = BigInt.zero()
}
if (event.transaction.gasPrice) {
order.gasPrice = event.transaction.gasPrice
} else {
order.gasPrice = BigInt.zero()
}
order.save()
token.save()
addOrder()
@ -91,6 +102,11 @@ export function handlerOrderReused(event: OrderReused): void {
if (!order) return
const reuseOrder = new OrderReuse(event.transaction.hash.toHex())
if (event.transaction.gasPrice)
reuseOrder.gasPrice = event.transaction.gasPrice
else reuseOrder.gasPrice = BigInt.zero()
if (event.receipt !== null) reuseOrder.gasUsed = event.receipt!.gasUsed
else reuseOrder.gasUsed = BigInt.zero()
reuseOrder.order = orderId
reuseOrder.caller = event.params.caller.toHexString()
reuseOrder.createdTimestamp = event.params.timestamp.toI32()
@ -235,6 +251,11 @@ export function handleProviderFee(event: ProviderFee): void {
orderReuse.tx = event.transaction.hash.toHex()
orderReuse.block = event.block.number.toI32()
orderReuse.caller = event.transaction.from.toHex()
if (event.transaction.gasPrice)
orderReuse.gasPrice = event.transaction.gasPrice
else orderReuse.gasPrice = BigInt.zero()
if (event.receipt !== null) orderReuse.gasUsed = event.receipt!.gasUsed
else orderReuse.gasUsed = BigInt.zero()
orderReuse.save()
}
}