diff --git a/abis/InstaConnectors.json b/abis/InstaConnectors.json new file mode 100644 index 0000000..b5c7fff --- /dev/null +++ b/abis/InstaConnectors.json @@ -0,0 +1,317 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "LogAddController", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "connector", + "type": "address" + } + ], + "name": "LogDisable", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "connector", + "type": "address" + } + ], + "name": "LogEnable", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "connector", + "type": "address" + } + ], + "name": "LogEnableStatic", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "LogRemoveController", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "chief", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "connectorArray", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "connectorCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "connectorLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "connectors", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_connector", + "type": "address" + } + ], + "name": "disable", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_userAddress", + "type": "address" + } + ], + "name": "disableChief", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_connector", + "type": "address" + } + ], + "name": "enable", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_userAddress", + "type": "address" + } + ], + "name": "enableChief", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_connector", + "type": "address" + } + ], + "name": "enableStatic", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "instaIndex", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "_connectors", + "type": "address[]" + } + ], + "name": "isConnector", + "outputs": [ + { + "internalType": "bool", + "name": "isOk", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "_connectors", + "type": "address[]" + } + ], + "name": "isStaticConnector", + "outputs": [ + { + "internalType": "bool", + "name": "isOk", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "staticConnectorArray", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "staticConnectorLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "staticConnectors", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/schema.graphql b/schema.graphql index 31f21a4..6279dab 100644 --- a/schema.graphql +++ b/schema.graphql @@ -24,7 +24,7 @@ type AccountModule @entity { address: String! - connectors: String! + connectors: InstaConnector! check: String @@ -40,3 +40,20 @@ type InstaIndex @entity { accountModules: [AccountModule!]! @derivedFrom(field: "instaIndex") } + +type InstaConnector @entity { + "Address of the InstaConnector contract. This contract has a list of connectors tracked." + id: ID! + + connectors: [Connector!]! @derivedFrom(field: "instaConnector") +} + +type Connector @entity { + id: ID! + + isStatic: Boolean! + + isEnabled: Boolean! + + instaConnector: InstaConnector! +} diff --git a/src/index.ts b/src/index.ts index d8bb306..6a60e42 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,3 +7,9 @@ export { handleSetBasics, handleBuild } from "./mappings/instaIndex"; + +export { + handleLogEnableConnector, + handleLogDisableConnector, + handleLogEnableStaticConnector +} from "./mappings/instaConnectors"; diff --git a/src/mappings/instaConnectors.ts b/src/mappings/instaConnectors.ts new file mode 100644 index 0000000..9def748 --- /dev/null +++ b/src/mappings/instaConnectors.ts @@ -0,0 +1,44 @@ +import { + LogDisable, + LogEnable, + LogEnableStatic +} from "../../generated/templates/InstaConnectors/InstaConnectors"; +import { getOrCreateConnector } from "../utils/helpers"; + +// - event: LogDisable(indexed address) +// handler: handleLogDisableConnector + +export function handleLogDisableConnector(event: LogDisable): void { + let connector = getOrCreateConnector(event.params.connector.toHexString()) + + connector.isEnabled = false; + connector.instaConnector = event.address.toHexString(); + + connector.save(); +} + +// - event: LogEnable(indexed address) +// handler: handleLogEnableConnector + +export function handleLogEnableConnector(event: LogEnable): void { + let connector = getOrCreateConnector(event.params.connector.toHexString()) + + connector.isEnabled = true; + connector.isStatic = false; + connector.instaConnector = event.address.toHexString(); + + connector.save(); +} + +// - event: LogEnableStatic(indexed address) +// handler: handleLogEnableStaticConnector + +export function handleLogEnableStaticConnector(event: LogEnableStatic): void { + let connector = getOrCreateConnector(event.params.connector.toHexString()) + + connector.isEnabled = true; + connector.isStatic = true; + connector.instaConnector = event.address.toHexString(); + + connector.save(); +} diff --git a/src/mappings/instaIndex.ts b/src/mappings/instaIndex.ts index f4ee151..348154d 100644 --- a/src/mappings/instaIndex.ts +++ b/src/mappings/instaIndex.ts @@ -1,4 +1,3 @@ -import { SmartAccount, User } from "../../generated/schema"; import { LogAccountCreated, LogNewAccount, @@ -13,9 +12,9 @@ import { getOrCreateAccountModule, getOrCreateUser, getOrCreateSmartAccount, + getOrCreateInstaConnector, getOrCreateInstaIndex } from "../utils/helpers"; - // - event: LogAccountCreated(address,indexed address,indexed address,indexed address) // handler: handleLogAccountCreated // Creation of new smart account for user @@ -44,9 +43,10 @@ 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 instaConnector = getOrCreateInstaConnector(event.params._connectors); accountModule.address = event.params._newAccount.toHexString(); - accountModule.connectors = event.params._connectors.toHexString(); + accountModule.connectors = instaConnector.id; accountModule.check = event.params._check.toHexString(); accountModule.save(); @@ -90,9 +90,10 @@ export function handleLogUpdateMaster(event: LogUpdateMaster): void { export function handleSetBasics(call: SetBasicsCall): void { let accountVersion = InstaIndex.bind(call.to).versionCount(); let accountModule = getOrCreateAccountModule(accountVersion.toString()); + let instaConnector = getOrCreateInstaConnector(call.inputs._connectors); accountModule.address = call.inputs._account.toHexString(); - accountModule.connectors = call.inputs._connectors.toHexString(); + accountModule.connectors = instaConnector.id; accountModule.save(); } diff --git a/src/utils/helpers/index.ts b/src/utils/helpers/index.ts index ffa953e..dc6505a 100644 --- a/src/utils/helpers/index.ts +++ b/src/utils/helpers/index.ts @@ -4,3 +4,8 @@ export { getOrCreateAccountModule, getOrCreateInstaIndex } from "./instaIndex"; + +export { + getOrCreateConnector, + getOrCreateInstaConnector +} from "./instaConnectors"; diff --git a/src/utils/helpers/instaConnectors.ts b/src/utils/helpers/instaConnectors.ts new file mode 100644 index 0000000..a3ada51 --- /dev/null +++ b/src/utils/helpers/instaConnectors.ts @@ -0,0 +1,32 @@ +import { InstaConnectors as ConnectorsTemplate } from "../../../generated/templates"; +import { InstaConnector, Connector } from "../../../generated/schema"; +import { Address } from "@graphprotocol/graph-ts"; + +export function getOrCreateInstaConnector( + addressId: Address +): InstaConnector { + let connectors = InstaConnector.load(addressId.toHexString()); + + if (connectors == null) { + connectors = new InstaConnector(addressId.toHexString()); + + connectors.save(); + + ConnectorsTemplate.create(addressId); + } + + return connectors as InstaConnector; +} + +export function getOrCreateConnector( + id: String, + createIfNotFound: boolean = true +): Connector { + let connector = Connector.load(id); + + if (connector == null && createIfNotFound) { + connector = new Connector(id); + } + + return connector as Connector; +} diff --git a/src/utils/helpers/instaIndex.ts b/src/utils/helpers/instaIndex.ts index 118451e..614af50 100644 --- a/src/utils/helpers/instaIndex.ts +++ b/src/utils/helpers/instaIndex.ts @@ -1,4 +1,9 @@ -import { User, SmartAccount, AccountModule, InstaIndex } from "../../../generated/schema"; +import { + User, + SmartAccount, + AccountModule, + InstaIndex +} from "../../../generated/schema"; export function getOrCreateUser( id: String, diff --git a/subgraph.yaml b/subgraph.yaml index 8d9ca26..3961994 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -38,3 +38,32 @@ dataSources: handler: handleSetBasics - function: build(address,uint256,address) handler: handleBuild +templates: + - name: InstaConnectors + kind: ethereum/contract + network: mainnet + source: + abi: InstaConnectors + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./src/index.ts + entities: + - InstaConnector + - Connector + abis: + - name: InstaConnectors + file: ./abis/InstaConnectors.json + eventHandlers: + - event: LogDisable(indexed address) + handler: handleLogDisableConnector + - event: LogEnable(indexed address) + handler: handleLogEnableConnector + - event: LogEnableStatic(indexed address) + handler: handleLogEnableStaticConnector + # - LogAddController(indexed address) + # - LogDisable(indexed address) + # - LogEnable(indexed address) + # - LogEnableStatic(indexed address) + # - LogRemoveController(indexed address)