graph added

This commit is contained in:
Richa-iitr 2022-09-05 00:02:08 +05:30
parent fd68056446
commit 84b52e23ca
9 changed files with 3955 additions and 72 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build
generated
node_modules

112
abis/InstaList.json Normal file
View File

@ -0,0 +1,112 @@
[
{
"inputs": [
{ "internalType": "address", "name": "_instaIndex", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"name": "accountAddr",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "accountID",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"name": "accountLink",
"outputs": [
{ "internalType": "address", "name": "first", "type": "address" },
{ "internalType": "address", "name": "last", "type": "address" },
{ "internalType": "uint64", "name": "count", "type": "uint64" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint64", "name": "", "type": "uint64" },
{ "internalType": "address", "name": "", "type": "address" }
],
"name": "accountList",
"outputs": [
{ "internalType": "address", "name": "prev", "type": "address" },
{ "internalType": "address", "name": "next", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "accounts",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "_owner", "type": "address" }
],
"name": "addAuth",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "_account", "type": "address" }
],
"name": "init",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "instaIndex",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "_owner", "type": "address" }
],
"name": "removeAuth",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "userLink",
"outputs": [
{ "internalType": "uint64", "name": "first", "type": "uint64" },
{ "internalType": "uint64", "name": "last", "type": "uint64" },
{ "internalType": "uint64", "name": "count", "type": "uint64" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "uint64", "name": "", "type": "uint64" }
],
"name": "userList",
"outputs": [
{ "internalType": "uint64", "name": "prev", "type": "uint64" },
{ "internalType": "uint64", "name": "next", "type": "uint64" }
],
"stateMutability": "view",
"type": "function"
}
]

View File

@ -112,5 +112,317 @@
"stateMutability": "payable",
"type": "function"
},
{ "stateMutability": "payable", "type": "receive" }
{ "stateMutability": "payable", "type": "receive" },
{
"inputs": [
{
"components": [
{ "internalType": "bytes32", "name": "name32", "type": "bytes32" },
{ "internalType": "bytes32", "name": "symbol32", "type": "bytes32" }
],
"internalType": "struct CometConfiguration.ExtConfiguration",
"name": "config",
"type": "tuple"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{ "inputs": [], "name": "BadAmount", "type": "error" },
{ "inputs": [], "name": "BadNonce", "type": "error" },
{ "inputs": [], "name": "BadSignatory", "type": "error" },
{ "inputs": [], "name": "InvalidInt104", "type": "error" },
{ "inputs": [], "name": "InvalidInt256", "type": "error" },
{ "inputs": [], "name": "InvalidUInt104", "type": "error" },
{ "inputs": [], "name": "InvalidUInt128", "type": "error" },
{ "inputs": [], "name": "InvalidUInt64", "type": "error" },
{ "inputs": [], "name": "InvalidValueS", "type": "error" },
{ "inputs": [], "name": "InvalidValueV", "type": "error" },
{ "inputs": [], "name": "NegativeNumber", "type": "error" },
{ "inputs": [], "name": "SignatureExpired", "type": "error" },
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"inputs": [
{ "internalType": "address", "name": "manager", "type": "address" },
{ "internalType": "bool", "name": "isAllowed_", "type": "bool" }
],
"name": "allow",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "manager", "type": "address" },
{ "internalType": "bool", "name": "isAllowed_", "type": "bool" },
{ "internalType": "uint256", "name": "nonce", "type": "uint256" },
{ "internalType": "uint256", "name": "expiry", "type": "uint256" },
{ "internalType": "uint8", "name": "v", "type": "uint8" },
{ "internalType": "bytes32", "name": "r", "type": "bytes32" },
{ "internalType": "bytes32", "name": "s", "type": "bytes32" }
],
"name": "allowBySig",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "spender", "type": "address" }
],
"name": "allowance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "approve",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "baseAccrualScale",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "baseIndexScale",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "baseTrackingAccrued",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "account", "type": "address" },
{ "internalType": "address", "name": "asset", "type": "address" }
],
"name": "collateralBalanceOf",
"outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "factorScale",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "manager", "type": "address" }
],
"name": "hasPermission",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "address", "name": "", "type": "address" }
],
"name": "isAllowed",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "liquidatorPoints",
"outputs": [
{ "internalType": "uint32", "name": "numAbsorbs", "type": "uint32" },
{ "internalType": "uint64", "name": "numAbsorbed", "type": "uint64" },
{ "internalType": "uint128", "name": "approxSpend", "type": "uint128" },
{ "internalType": "uint32", "name": "_reserved", "type": "uint32" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "maxAssets",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "priceScale",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalsBasic",
"outputs": [
{
"components": [
{
"internalType": "uint64",
"name": "baseSupplyIndex",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "baseBorrowIndex",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "trackingSupplyIndex",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "trackingBorrowIndex",
"type": "uint64"
},
{
"internalType": "uint104",
"name": "totalSupplyBase",
"type": "uint104"
},
{
"internalType": "uint104",
"name": "totalBorrowBase",
"type": "uint104"
},
{
"internalType": "uint40",
"name": "lastAccrualTime",
"type": "uint40"
},
{ "internalType": "uint8", "name": "pauseFlags", "type": "uint8" }
],
"internalType": "struct CometStorage.TotalsBasic",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "totalsCollateral",
"outputs": [
{
"internalType": "uint128",
"name": "totalSupplyAsset",
"type": "uint128"
},
{ "internalType": "uint128", "name": "_reserved", "type": "uint128" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "userBasic",
"outputs": [
{ "internalType": "int104", "name": "principal", "type": "int104" },
{
"internalType": "uint64",
"name": "baseTrackingIndex",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "baseTrackingAccrued",
"type": "uint64"
},
{ "internalType": "uint16", "name": "assetsIn", "type": "uint16" },
{ "internalType": "uint8", "name": "_reserved", "type": "uint8" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "address", "name": "", "type": "address" }
],
"name": "userCollateral",
"outputs": [
{ "internalType": "uint128", "name": "balance", "type": "uint128" },
{ "internalType": "uint128", "name": "_reserved", "type": "uint128" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "userNonce",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "version",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
}
]

View File

@ -1,6 +1,41 @@
type ExampleEntity @entity {
type Owner @entity {
id: ID!
count: BigInt!
previousAdmin: Bytes! # address
newAdmin: Bytes! # address
address: Bytes!
manager: [Manager!]! @derivedFrom(field: "owner")
}
type Manager @entity {
id: ID!
address: Bytes!
owner: Owner!
isAllowed: Boolean!
isDSA: Boolean!
transactionData: TransactionData!
}
type TransactionData @entity {
# transaction hash
id: ID!
# transaction index
txnIndex: BigInt!
# transaction log index
txnLogIndex: BigInt!
# from
from: Bytes!
# to
to: Bytes
# input
input: Bytes!
# block number
blockNumber: BigInt!
# timestamp
timestamp: BigInt!
# gas
blockGasUsed: BigInt!
#gas price
gasPrice: BigInt!
# gas limit
gasLimit: BigInt!
#value
value: BigInt!
}

View File

@ -1,55 +0,0 @@
import { BigInt } from "@graphprotocol/graph-ts"
import {
cUSDCv3,
AdminChanged,
BeaconUpgraded,
Upgraded
} from "../generated/cUSDCv3/cUSDCv3"
import { ExampleEntity } from "../generated/schema"
export function handleAdminChanged(event: AdminChanged): void {
// Entities can be loaded from the store using a string ID; this ID
// needs to be unique across all entities of the same type
let entity = ExampleEntity.load(event.transaction.from.toHex())
// Entities only exist after they have been saved to the store;
// `null` checks allow to create entities on demand
if (!entity) {
entity = new ExampleEntity(event.transaction.from.toHex())
// Entity fields can be set using simple assignments
entity.count = BigInt.fromI32(0)
}
// BigInt and BigDecimal math are supported
entity.count = entity.count + BigInt.fromI32(1)
// Entity fields can be set based on event parameters
entity.previousAdmin = event.params.previousAdmin
entity.newAdmin = event.params.newAdmin
// Entities can be written to the store with `.save()`
entity.save()
// Note: If a handler doesn't require existing field values, it is faster
// _not_ to load the entity from the store. Instead, create it fresh with
// `new Entity(...)`, set the fields that should be updated and save the
// entity back to the store. Fields that were not set or unset remain
// unchanged, allowing for partial updates to be applied.
// It is also possible to access smart contracts from mappings. For
// example, the contract that has emitted the event can be connected to
// with:
//
// let contract = Contract.bind(event.address)
//
// The following functions can then be called on this contract to access
// state variables and other data:
//
// - contract.admin(...)
// - contract.implementation(...)
}
export function handleBeaconUpgraded(event: BeaconUpgraded): void {}
export function handleUpgraded(event: Upgraded): void {}

View File

@ -0,0 +1,38 @@
import {
cUSDCv3,
Approval
} from "../generated/cUSDCv3/cUSDCv3"
import { createOrLoadManager, createOrLoadOwner, createOrLoadTransaction, isDSA, ZERO } from "./utils";
export function handleManagerToggled(event: Approval): void {
let ownerID = event.params.owner.toHexString();
let managerID = event.params.spender.toHexString() + "#" + event.params.owner.toHexString();
let transactionID = event.transaction.hash.toHexString() + "#" + event.logIndex.toString();
let transactionData = createOrLoadTransaction(transactionID);
transactionData.txnIndex = event.transaction.index;
transactionData.txnLogIndex = event.transactionLogIndex;
transactionData.from = event.transaction.from;
transactionData.to = event.transaction.to;
transactionData.input = event.transaction.input;
transactionData.blockNumber = event.block.number;
transactionData.timestamp = event.block.timestamp;
transactionData.gasLimit = event.block.gasLimit;
transactionData.blockGasUsed = event.block.gasUsed;
transactionData.gasPrice = event.transaction.gasPrice;
transactionData.value = event.transaction.value;
let manager = createOrLoadManager(managerID);
manager.address = event.params.spender;
manager.isAllowed = event.params.amount == ZERO ? false : true;
manager.owner = ownerID;
manager.isDSA = isDSA(event.params.spender);
manager.transactionData = transactionID;
let owner = createOrLoadOwner(ownerID);
owner.address = event.params.owner;
transactionData.save();
manager.save();
owner.save();
}

65
src/utils.ts Normal file
View File

@ -0,0 +1,65 @@
import {
Address,
BigInt,
Bytes,
DataSourceContext,
} from "@graphprotocol/graph-ts";
import { Approval } from "../generated/cUSDCv3/cUSDCv3";
import { TransactionData, Owner, Manager } from "../generated/schema";
import { InstaList } from "../generated/cUSDCv3/InstaList";
export const ZERO = new BigInt(0);
export function isDSA(account: Address): boolean {
let listAddress = Address.fromBytes(
Address.fromHexString("0x4c8a1BEb8a87765788946D6B19C6C6355194AbEb")
);
let instaList = InstaList.bind(listAddress);
let isDSA = instaList.accountID(account) == ZERO ? false : true;
return isDSA;
}
//loads or creates smart owner
export function createOrLoadOwner(id: string): Owner {
let account = Owner.load(id);
if (account == null) {
account = new Owner(id);
account.address = new Address(0);
}
return account;
}
//loads or creates smart owner
export function createOrLoadManager(id: string): Manager {
let account = Manager.load(id);
if (account == null) {
account = new Manager(id);
account.address = new Address(0);
account.owner = "";
account.isAllowed = false;
account.isDSA = false;
account.transactionData = "";
}
return account;
}
//creates instance for new transaction or loads existing one
export function createOrLoadTransaction(id: string): TransactionData {
let txn = TransactionData.load(id);
if (txn == null) {
txn = new TransactionData(id);
txn.txnIndex = ZERO;
txn.txnLogIndex = ZERO;
txn.from = new Address(0);
txn.to = new Address(0);
txn.input = new Bytes(0);
txn.blockNumber = ZERO;
txn.timestamp = ZERO;
txn.blockGasUsed = ZERO;
txn.gasLimit = ZERO;
txn.gasPrice = ZERO;
txn.value = ZERO;
}
return txn;
}

View File

@ -1,29 +1,28 @@
specVersion: 0.0.1
specVersion: 0.0.5
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum
name: undefined
name: cUSDCv3
network: mainnet
source:
address: "0xc3d688B66703497DAA19211EEdff47f25384cdc3"
abi: cUSDCv3
startBlock: 15331500
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
entities:
- AdminChanged
- BeaconUpgraded
- Upgraded
- Owner
- Manager
- Transaction
abis:
- name: cUSDCv3
file: ./abis/cUSDCv3.json
- name: InstaList
file: ./abis/InstaList.json
eventHandlers:
- event: AdminChanged(address,address)
handler: handleAdminChanged
- event: BeaconUpgraded(indexed address)
handler: handleBeaconUpgraded
- event: Upgraded(indexed address)
handler: handleUpgraded
file: ./src/c-usd-cv-3.ts
- event: Approval(indexed address,indexed address,uint256)
handler: handleManagerToggled
file: ./src/compound-v3-managers.ts

3374
yarn.lock Normal file

File diff suppressed because it is too large Load Diff