Skip to content

Commit

Permalink
Tasks: Add environment to relayed executions (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Facu Spagnuolo <[email protected]>
  • Loading branch information
PatricioHenderson and facuspagnuolo authored Sep 12, 2023
1 parent cc78d86 commit 2ed5886
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Environment @entity {
priceOracles: [PriceOracle!] @derivedFrom(field: "environment")
smartVaults: [SmartVault!] @derivedFrom(field: "environment")
tasks: [Task!] @derivedFrom(field: "environment")
relayedExecutions: [RelayedExecution!] @derivedFrom(field: "environment")
}

type SmartVault @entity {
Expand Down Expand Up @@ -168,6 +169,7 @@ type RelayedExecution @entity {
sender: String!
executedAt: BigInt!
smartVault: SmartVault!
environment: Environment!
task: Task!
index: BigInt!
succeeded: Boolean!
Expand Down
6 changes: 5 additions & 1 deletion src/Relayer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Address, log } from '@graphprotocol/graph-ts'

import { TaskExecuted } from '../types/Relayer/Relayer'
import { Movement, RelayedExecution, Transaction } from '../types/schema'
import { Movement, RelayedExecution, Task, Transaction } from '../types/schema'
import { Task as TaskContract } from '../types/templates/Task/Task'

export function handleTaskExecuted(event: TaskExecuted): void {
const task = Task.load(event.params.task.toHexString())
if (task == null) return log.warning('Missing task entity {}', [event.params.task.toHexString()])

const executionId = event.transaction.hash.toHexString() + '#' + event.params.index.toString()
const execution = new RelayedExecution(executionId)
execution.hash = event.transaction.hash.toHexString()
Expand All @@ -18,6 +21,7 @@ export function handleTaskExecuted(event: TaskExecuted): void {
execution.gasUsed = event.params.gas
execution.gasPrice = event.transaction.gasPrice
execution.costNative = event.transaction.gasPrice.times(event.params.gas)
execution.environment = task.environment
execution.save()

// eslint-disable-next-line no-constant-condition
Expand Down

0 comments on commit 2ed5886

Please sign in to comment.