From 17aba58915310ad14495468b2fd738b7d0914570 Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Fri, 22 May 2020 11:45:22 -0300 Subject: [PATCH] Added build call handling to get account module data for smart accounts --- schema.graphql | 6 +++++- src/index.ts | 3 ++- src/mappings/instaIndex.ts | 35 +++++++++++++++++++++++++---------- subgraph.yaml | 2 ++ 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/schema.graphql b/schema.graphql index 8207ec4..31f21a4 100644 --- a/schema.graphql +++ b/schema.graphql @@ -11,9 +11,11 @@ type SmartAccount @entity { owner: User! - creator: User! + creator: User origin: String! + + accountModule: AccountModule } type AccountModule @entity { @@ -27,6 +29,8 @@ type AccountModule @entity { check: String instaIndex: InstaIndex! + + accountsCloned: [SmartAccount!]! @derivedFrom(field: "accountModule") } type InstaIndex @entity { diff --git a/src/index.ts b/src/index.ts index 7da5950..d8bb306 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,5 +4,6 @@ export { handleLogNewCheck, handleLogNewMaster, handleLogUpdateMaster, - handleSetBasics + handleSetBasics, + handleBuild } from "./mappings/instaIndex"; diff --git a/src/mappings/instaIndex.ts b/src/mappings/instaIndex.ts index 8f9e680..f4ee151 100644 --- a/src/mappings/instaIndex.ts +++ b/src/mappings/instaIndex.ts @@ -6,6 +6,7 @@ import { LogNewMaster, LogUpdateMaster, SetBasicsCall, + BuildCall, InstaIndex } from "../../generated/InstaIndex/InstaIndex"; import { @@ -13,7 +14,7 @@ import { getOrCreateUser, getOrCreateSmartAccount, getOrCreateInstaIndex -} from '../utils/helpers' +} from "../utils/helpers"; // - event: LogAccountCreated(address,indexed address,indexed address,indexed address) // handler: handleLogAccountCreated @@ -21,9 +22,11 @@ import { // event LogAccountCreated(address sender, address indexed owner, address indexed account, address indexed origin); export function handleLogAccountCreated(event: LogAccountCreated): void { - let smartAccount = getOrCreateSmartAccount(event.params.account.toHexString()); - let owner = getOrCreateUser(event.params.owner.toHexString()) - let sender = getOrCreateUser(event.params.sender.toHexString()) + let smartAccount = getOrCreateSmartAccount( + event.params.account.toHexString() + ); + let owner = getOrCreateUser(event.params.owner.toHexString()); + let sender = getOrCreateUser(event.params.sender.toHexString()); smartAccount.owner = owner.id; smartAccount.creator = sender.id; @@ -40,7 +43,7 @@ export function handleLogAccountCreated(event: LogAccountCreated): void { export function handleLogNewAccount(event: LogNewAccount): void { // current account version has to be retrieved from the contract let accountVersion = InstaIndex.bind(event.address).versionCount(); - let accountModule = getOrCreateAccountModule(accountVersion.toString()) + let accountModule = getOrCreateAccountModule(accountVersion.toString()); accountModule.address = event.params._newAccount.toHexString(); accountModule.connectors = event.params._connectors.toHexString(); @@ -53,7 +56,9 @@ export function handleLogNewAccount(event: LogNewAccount): void { // handler: handleLogNewCheck export function handleLogNewCheck(event: LogNewCheck): void { - let accountModule = getOrCreateAccountModule(event.params.accountVersion.toString()); + let accountModule = getOrCreateAccountModule( + event.params.accountVersion.toString() + ); accountModule.check = event.params.check.toHexString(); @@ -82,15 +87,25 @@ export function handleLogUpdateMaster(event: LogUpdateMaster): void { index.save(); } -// - event: LogUpdateMaster(indexed address) -// handler: handleLogUpdateMaster - export function handleSetBasics(call: SetBasicsCall): void { let accountVersion = InstaIndex.bind(call.to).versionCount(); - let accountModule = getOrCreateAccountModule(accountVersion.toString()) + let accountModule = getOrCreateAccountModule(accountVersion.toString()); accountModule.address = call.inputs._account.toHexString(); accountModule.connectors = call.inputs._connectors.toHexString(); accountModule.save(); } + +export function handleBuild(call: BuildCall): void { + let smartAccount = getOrCreateSmartAccount( + call.outputs._account.toHexString() + ); + let owner = getOrCreateUser(call.inputs._owner.toHexString()); + + smartAccount.owner = owner.id; + smartAccount.origin = call.inputs._origin.toHexString(); + smartAccount.accountModule = call.inputs.accountVersion.toString(); + + smartAccount.save(); +} diff --git a/subgraph.yaml b/subgraph.yaml index 5eecd55..8d9ca26 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -36,3 +36,5 @@ dataSources: callHandlers: - function: setBasics(address,address,address,address) handler: handleSetBasics + - function: build(address,uint256,address) + handler: handleBuild