Skip to content

Commit

Permalink
schema: implement task handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Aug 15, 2023
1 parent 1f07ae4 commit 5cd2b43
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type Task @entity {
implementation: Implementation!
environment: Environment!
smartVault: SmartVault!
nextBalanceConnector: String!
previousBalanceConnector: String!
}

type Movement @entity {
Expand Down
2 changes: 2 additions & 0 deletions src/Deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export function handleTaskDeployed(event: TaskDeployed): void {
task.implementation = implementation.id
task.environment = environment.id
task.smartVault = getSmartVault(event.params.instance).toHexString()
task.previousBalanceConnector = '0x0000000000000000000000000000000000000000000000000000000000000000'
task.nextBalanceConnector = '0x0000000000000000000000000000000000000000000000000000000000000000'
task.save()
}

Expand Down
12 changes: 12 additions & 0 deletions src/Task.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { Address, log } from '@graphprotocol/graph-ts'

import { Task } from '../types/schema'

import { BalanceConnectorsSet } from '../types/templates/Task/Task'
import { Task as TaskContract } from '../types/templates/Task/Task'

export function handleBalanceConnectorsSet(event: BalanceConnectorsSet): void {
let task = Task.load(event.address.toHexString())
if (task == null) return log.warning('Missing task entity {}', [event.address.toHexString()])

task.previousBalanceConnector = event.params.previous.toHexString()
task.nextBalanceConnector = event.params.next.toHexString()
task.save()
}

export function getSmartVault(address: Address): Address {
let taskContract = TaskContract.bind(address)
let smartVaultCall = taskContract.try_smartVault()
Expand Down
3 changes: 3 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@ templates:
abis:
- name: Task
file: ./node_modules/@mimic-fi/v3-tasks/artifacts/contracts/interfaces/ITask.sol/ITask.json
eventHandlers:
- event: BalanceConnectorsSet(indexed bytes32,indexed bytes32)
handler: handleBalanceConnectorsSet
file: ./src/Task.ts

0 comments on commit 5cd2b43

Please sign in to comment.