Added InstaConnectors and Connector basic support and indexing

This commit is contained in:
Juan Manuel Rodriguez Defago 2020-05-22 13:35:24 -03:00
parent 17aba58915
commit 64e8fc41d1
9 changed files with 462 additions and 6 deletions

317
abis/InstaConnectors.json Normal file
View File

@ -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"
}
]

View File

@ -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!
}

View File

@ -7,3 +7,9 @@ export {
handleSetBasics,
handleBuild
} from "./mappings/instaIndex";
export {
handleLogEnableConnector,
handleLogDisableConnector,
handleLogEnableStaticConnector
} from "./mappings/instaConnectors";

View File

@ -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();
}

View File

@ -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();
}

View File

@ -4,3 +4,8 @@ export {
getOrCreateAccountModule,
getOrCreateInstaIndex
} from "./instaIndex";
export {
getOrCreateConnector,
getOrCreateInstaConnector
} from "./instaConnectors";

View File

@ -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;
}

View File

@ -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,

View File

@ -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)