diff --git a/schema.graphql b/schema.graphql index 9cafc57..f12bd33 100644 --- a/schema.graphql +++ b/schema.graphql @@ -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 { diff --git a/src/mappings/erc20Templates.ts b/src/mappings/erc20Templates.ts index 89de379..d1212ef 100644 --- a/src/mappings/erc20Templates.ts +++ b/src/mappings/erc20Templates.ts @@ -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() } }