mirror of
https://github.com/tornadocash/landing-subgraph.git
synced 2024-11-22 01:36:52 +01:00
init
This commit is contained in:
parent
0406c94953
commit
ad26b2f372
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
build
|
||||
generated
|
@ -4,10 +4,10 @@
|
||||
"scripts": {
|
||||
"codegen": "graph codegen",
|
||||
"build": "graph build",
|
||||
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ dan1kov/test",
|
||||
"create-local": "graph create --node http://localhost:8020/ dan1kov/test",
|
||||
"remove-local": "graph remove --node http://localhost:8020/ dan1kov/test",
|
||||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 dan1kov/test"
|
||||
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ tornadocash/landing-subgraph",
|
||||
"create-local": "graph create --node http://localhost:8020/ tornadocash/landing-subgraph",
|
||||
"remove-local": "graph remove --node http://localhost:8020/ tornadocash/landing-subgraph",
|
||||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 tornadocash/landing-subgraph"
|
||||
},
|
||||
"dependencies": {
|
||||
"@graphprotocol/graph-cli": "0.20.0",
|
||||
|
@ -1,6 +1,11 @@
|
||||
type ExampleEntity @entity {
|
||||
type Token @entity {
|
||||
id: ID!
|
||||
count: BigInt!
|
||||
commitment: Bytes! # bytes32
|
||||
leafIndex: BigInt! # uint32
|
||||
depositedAmount: BigInt!
|
||||
totalDeposits: Int!
|
||||
totalUsers: Int!
|
||||
}
|
||||
|
||||
type User @entity {
|
||||
id: ID! # Ethereum address
|
||||
txCount: Int!
|
||||
}
|
||||
|
24
src/classes/Token.ts
Normal file
24
src/classes/Token.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { store, BigInt } from "@graphprotocol/graph-ts";
|
||||
import { Token as generatedToken } from "../../generated/schema";
|
||||
|
||||
export class Token extends generatedToken {
|
||||
constructor(name: string) {
|
||||
super(name);
|
||||
this.depositedAmount = BigInt.fromI32(0);
|
||||
this.totalDeposits = 0;
|
||||
this.totalUsers = 0;
|
||||
}
|
||||
|
||||
static load(id: string): Token | null {
|
||||
return store.get("Token", id) as Token | null;
|
||||
}
|
||||
|
||||
addDeposit(value: BigInt): void {
|
||||
this.totalDeposits = this.totalDeposits + 1;
|
||||
this.depositedAmount = this.depositedAmount.plus(value);
|
||||
}
|
||||
|
||||
addUser(): void {
|
||||
this.totalUsers = this.totalUsers + 1;
|
||||
}
|
||||
}
|
17
src/classes/User.ts
Normal file
17
src/classes/User.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { store } from "@graphprotocol/graph-ts";
|
||||
import { User as generatedUser } from "../../generated/schema";
|
||||
|
||||
export class User extends generatedUser {
|
||||
constructor(name: string) {
|
||||
super(name);
|
||||
this.txCount = 0;
|
||||
}
|
||||
|
||||
static load(id: string): User | null {
|
||||
return store.get("User", id) as User | null;
|
||||
}
|
||||
|
||||
addTx(): void {
|
||||
this.txCount = this.txCount + 1;
|
||||
}
|
||||
}
|
2
src/classes/index.ts
Normal file
2
src/classes/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { Token } from "./Token";
|
||||
export { User } from "./User";
|
@ -1,66 +0,0 @@
|
||||
import { BigInt } from "@graphprotocol/graph-ts"
|
||||
import { Contract, Deposit, Withdrawal } from "../generated/Contract/Contract"
|
||||
import { ExampleEntity } from "../generated/schema"
|
||||
|
||||
export function handleDeposit(event: Deposit): 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 == null) {
|
||||
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.commitment = event.params.commitment
|
||||
entity.leafIndex = event.params.leafIndex
|
||||
|
||||
// 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.nullifierHashes(...)
|
||||
// - contract.verifier(...)
|
||||
// - contract.hashLeftRight(...)
|
||||
// - contract.FIELD_SIZE(...)
|
||||
// - contract.levels(...)
|
||||
// - contract.operator(...)
|
||||
// - contract.isKnownRoot(...)
|
||||
// - contract.commitments(...)
|
||||
// - contract.denomination(...)
|
||||
// - contract.currentRootIndex(...)
|
||||
// - contract.isSpentArray(...)
|
||||
// - contract.isMigrated(...)
|
||||
// - contract.getLastRoot(...)
|
||||
// - contract.roots(...)
|
||||
// - contract.ROOT_HISTORY_SIZE(...)
|
||||
// - contract.isSpent(...)
|
||||
// - contract.zeros(...)
|
||||
// - contract.ZERO_VALUE(...)
|
||||
// - contract.filledSubtrees(...)
|
||||
// - contract.nextIndex(...)
|
||||
}
|
||||
|
||||
export function handleWithdrawal(event: Withdrawal): void {}
|
26
src/mappings/core.ts
Normal file
26
src/mappings/core.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { ethereum } from "@graphprotocol/graph-ts";
|
||||
import { Token, User } from "../classes";
|
||||
|
||||
export function handleTornadoDeposit(
|
||||
tokenId: string,
|
||||
event: ethereum.Event
|
||||
): void {
|
||||
let token = Token.load(tokenId);
|
||||
if (token == null) {
|
||||
token = new Token(tokenId);
|
||||
}
|
||||
|
||||
token.addDeposit(event.transaction.value);
|
||||
|
||||
let userId = event.transaction.from.toHex();
|
||||
let user = User.load(userId);
|
||||
if (user == null) {
|
||||
user = new User(userId);
|
||||
token.addUser();
|
||||
}
|
||||
|
||||
user.addTx();
|
||||
|
||||
token.save();
|
||||
user.save();
|
||||
}
|
6
src/mappings/instances/eth/01.ts
Normal file
6
src/mappings/instances/eth/01.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { handleTornadoDeposit } from "../../core";
|
||||
import { Deposit } from "../../../../generated/eth01/Tornado";
|
||||
|
||||
export function handleDeposit(event: Deposit): void {
|
||||
handleTornadoDeposit("ETH", event);
|
||||
}
|
6
src/mappings/instances/eth/1.ts
Normal file
6
src/mappings/instances/eth/1.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { handleTornadoDeposit } from "../../core";
|
||||
import { Deposit } from "../../../../generated/eth1/Tornado";
|
||||
|
||||
export function handleDeposit(event: Deposit): void {
|
||||
handleTornadoDeposit("ETH", event);
|
||||
}
|
6
src/mappings/instances/eth/10.ts
Normal file
6
src/mappings/instances/eth/10.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { handleTornadoDeposit } from "../../core";
|
||||
import { Deposit } from "../../../../generated/eth10/Tornado";
|
||||
|
||||
export function handleDeposit(event: Deposit): void {
|
||||
handleTornadoDeposit("ETH", event);
|
||||
}
|
6
src/mappings/instances/eth/100.ts
Normal file
6
src/mappings/instances/eth/100.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { handleTornadoDeposit } from "../../core";
|
||||
import { Deposit } from "../../../../generated/eth100/Tornado";
|
||||
|
||||
export function handleDeposit(event: Deposit): void {
|
||||
handleTornadoDeposit("ETH", event);
|
||||
}
|
@ -1,26 +1,87 @@
|
||||
specVersion: 0.0.1
|
||||
specVersion: 0.0.2
|
||||
schema:
|
||||
file: ./schema.graphql
|
||||
dataSources:
|
||||
- kind: ethereum/contract
|
||||
name: Contract
|
||||
name: eth01
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x12D66f87A04A9E220743712cE6d9bB1B5616B8Fc"
|
||||
abi: Contract
|
||||
abi: Tornado
|
||||
startBlock: 9116966
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
apiVersion: 0.0.2
|
||||
apiVersion: 0.0.4
|
||||
language: wasm/assemblyscript
|
||||
entities:
|
||||
- Deposit
|
||||
- Withdrawal
|
||||
# - Withdrawal
|
||||
abis:
|
||||
- name: Contract
|
||||
file: ./abis/Contract.json
|
||||
- name: Tornado
|
||||
file: ./abis/Tornado.json
|
||||
eventHandlers:
|
||||
- event: Deposit(indexed bytes32,uint32,uint256)
|
||||
handler: handleDeposit
|
||||
- event: Withdrawal(address,bytes32,indexed address,uint256)
|
||||
handler: handleWithdrawal
|
||||
file: ./src/mapping.ts
|
||||
# - event: Withdrawal(address,bytes32,indexed address,uint256)
|
||||
# handler: handleWithdrawal
|
||||
file: ./src/mappings/instances/eth/01.ts
|
||||
- kind: ethereum/contract
|
||||
name: eth1
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x47CE0C6eD5B0Ce3d3A51fdb1C52DC66a7c3c2936"
|
||||
abi: Tornado
|
||||
startBlock: 9116966
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
apiVersion: 0.0.4
|
||||
language: wasm/assemblyscript
|
||||
entities:
|
||||
- Deposit
|
||||
abis:
|
||||
- name: Tornado
|
||||
file: ./abis/Tornado.json
|
||||
eventHandlers:
|
||||
- event: Deposit(indexed bytes32,uint32,uint256)
|
||||
handler: handleDeposit
|
||||
file: ./src/mappings/instances/eth/1.ts
|
||||
- kind: ethereum/contract
|
||||
name: eth10
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x910Cbd523D972eb0a6f4cAe4618aD62622b39DbF"
|
||||
abi: Tornado
|
||||
startBlock: 9116966
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
apiVersion: 0.0.4
|
||||
language: wasm/assemblyscript
|
||||
entities:
|
||||
- Deposit
|
||||
abis:
|
||||
- name: Tornado
|
||||
file: ./abis/Tornado.json
|
||||
eventHandlers:
|
||||
- event: Deposit(indexed bytes32,uint32,uint256)
|
||||
handler: handleDeposit
|
||||
file: ./src/mappings/instances/eth/10.ts
|
||||
- kind: ethereum/contract
|
||||
name: eth100
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0xA160cdAB225685dA1d56aa342Ad8841c3b53f291"
|
||||
abi: Tornado
|
||||
startBlock: 9116966
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
apiVersion: 0.0.4
|
||||
language: wasm/assemblyscript
|
||||
entities:
|
||||
- Deposit
|
||||
abis:
|
||||
- name: Tornado
|
||||
file: ./abis/Tornado.json
|
||||
eventHandlers:
|
||||
- event: Deposit(indexed bytes32,uint32,uint256)
|
||||
handler: handleDeposit
|
||||
file: ./src/mappings/instances/eth/100.ts
|
||||
|
Loading…
Reference in New Issue
Block a user