init: sub graph for bsc

This commit is contained in:
nikdementev 2021-06-07 13:43:31 +03:00
commit f770855c0a
No known key found for this signature in database
GPG Key ID: 769B05D57CF16FE2
24 changed files with 3994 additions and 0 deletions

21
abis/Echoer.json Normal file
View File

@ -0,0 +1,21 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "who",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "Echo",
"type": "event"
}
]

58
abis/Instance.json Normal file
View File

@ -0,0 +1,58 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "uint32",
"name": "leafIndex",
"type": "uint32"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
}
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "nullifierHash",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "fee",
"type": "uint256"
}
],
"name": "Withdrawal",
"type": "event"
}
]

21
abis/Proxy.json Normal file
View File

@ -0,0 +1,21 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "encryptedNote",
"type": "bytes"
}
],
"name": "EncryptedNote",
"type": "event"
}
]

BIN
build/Echoer/Echoer.wasm Normal file

Binary file not shown.

View File

@ -0,0 +1,21 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "who",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "Echo",
"type": "event"
}
]

Binary file not shown.

View File

@ -0,0 +1,58 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "uint32",
"name": "leafIndex",
"type": "uint32"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
}
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "nullifierHash",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "address",
"name": "relayer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "fee",
"type": "uint256"
}
],
"name": "Withdrawal",
"type": "event"
}
]

BIN
build/Proxy/Proxy.wasm Normal file

Binary file not shown.

View File

@ -0,0 +1,21 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "encryptedNote",
"type": "bytes"
}
],
"name": "EncryptedNote",
"type": "event"
}
]

38
build/schema.graphql Normal file
View File

@ -0,0 +1,38 @@
type Deposit @entity {
id: ID!
index: BigInt!
amount: String!
currency: String!
commitment: Bytes!
timestamp: BigInt!
blockNumber: BigInt!
transactionHash: Bytes!
}
type Withdrawal @entity {
id: ID!
to: Bytes!
fee: BigInt!
index: BigInt!
amount: String!
currency: String!
nullifier: Bytes!
timestamp: BigInt!
blockNumber: BigInt!
transactionHash: Bytes!
}
type EncryptedNote @entity {
id: ID!
index: BigInt!
blockNumber: BigInt!
encryptedNote: Bytes!
transactionHash: Bytes!
}
type NoteAccount @entity {
id: ID!
index: BigInt!
address: Bytes!
encryptedAccount: Bytes!
}

67
build/subgraph.yaml Normal file
View File

@ -0,0 +1,67 @@
specVersion: 0.0.2
schema:
file: schema.graphql
dataSources:
- kind: ethereum/contract
name: Proxy
network: bsc
source:
address: "0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7"
abi: Proxy
startBlock: 7941563
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- EncryptedNote
abis:
- name: Proxy
file: Proxy/abis/Proxy.json
eventHandlers:
- event: EncryptedNote(indexed address,bytes)
handler: handleEncryptedNote
file: Proxy/Proxy.wasm
- kind: ethereum/contract
name: Echoer
network: bsc
source:
address: "0x60eaCBd5535ADB86955A0154E44Aded78F161643"
abi: Echoer
startBlock: 7941563
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- NoteAccount
abis:
- name: Echoer
file: Echoer/abis/Echoer.json
eventHandlers:
- event: Echo(indexed address,bytes)
handler: handleEcho
file: Echoer/Echoer.wasm
- kind: ethereum/contract
name: Instance
network: bsc
source:
address: "0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d"
abi: Instance
startBlock: 7941563
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- Deposit
- Withdrawal
abis:
- name: Instance
file: Instance/abis/Instance.json
eventHandlers:
- event: Deposit(indexed bytes32,uint32,uint256)
handler: handleDeposit
- event: Withdrawal(address,bytes32,indexed address,uint256)
handler: handleWithdrawal
file: Instance/Instance.wasm

View File

@ -0,0 +1,39 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
ethereum,
JSONValue,
TypedMap,
Entity,
Bytes,
Address,
BigInt
} from "@graphprotocol/graph-ts";
export class Echo extends ethereum.Event {
get params(): Echo__Params {
return new Echo__Params(this);
}
}
export class Echo__Params {
_event: Echo;
constructor(event: Echo) {
this._event = event;
}
get who(): Address {
return this._event.parameters[0].value.toAddress();
}
get data(): Bytes {
return this._event.parameters[1].value.toBytes();
}
}
export class Echoer extends ethereum.SmartContract {
static bind(address: Address): Echoer {
return new Echoer("Echoer", address);
}
}

View File

@ -0,0 +1,73 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
ethereum,
JSONValue,
TypedMap,
Entity,
Bytes,
Address,
BigInt
} from "@graphprotocol/graph-ts";
export class Deposit extends ethereum.Event {
get params(): Deposit__Params {
return new Deposit__Params(this);
}
}
export class Deposit__Params {
_event: Deposit;
constructor(event: Deposit) {
this._event = event;
}
get commitment(): Bytes {
return this._event.parameters[0].value.toBytes();
}
get leafIndex(): BigInt {
return this._event.parameters[1].value.toBigInt();
}
get timestamp(): BigInt {
return this._event.parameters[2].value.toBigInt();
}
}
export class Withdrawal extends ethereum.Event {
get params(): Withdrawal__Params {
return new Withdrawal__Params(this);
}
}
export class Withdrawal__Params {
_event: Withdrawal;
constructor(event: Withdrawal) {
this._event = event;
}
get to(): Address {
return this._event.parameters[0].value.toAddress();
}
get nullifierHash(): Bytes {
return this._event.parameters[1].value.toBytes();
}
get relayer(): Address {
return this._event.parameters[2].value.toAddress();
}
get fee(): BigInt {
return this._event.parameters[3].value.toBigInt();
}
}
export class Instance extends ethereum.SmartContract {
static bind(address: Address): Instance {
return new Instance("Instance", address);
}
}

39
generated/Proxy/Proxy.ts Normal file
View File

@ -0,0 +1,39 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
ethereum,
JSONValue,
TypedMap,
Entity,
Bytes,
Address,
BigInt
} from "@graphprotocol/graph-ts";
export class EncryptedNote extends ethereum.Event {
get params(): EncryptedNote__Params {
return new EncryptedNote__Params(this);
}
}
export class EncryptedNote__Params {
_event: EncryptedNote;
constructor(event: EncryptedNote) {
this._event = event;
}
get sender(): Address {
return this._event.parameters[0].value.toAddress();
}
get encryptedNote(): Bytes {
return this._event.parameters[1].value.toBytes();
}
}
export class Proxy extends ethereum.SmartContract {
static bind(address: Address): Proxy {
return new Proxy("Proxy", address);
}
}

3
generated/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './Proxy/Proxy'
export * from './Echoer/Echoer'
export * from './Instance/Instance'

344
generated/schema.ts Normal file
View File

@ -0,0 +1,344 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
TypedMap,
Entity,
Value,
ValueKind,
store,
Address,
Bytes,
BigInt,
BigDecimal
} from "@graphprotocol/graph-ts";
export class Deposit extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save Deposit entity without an ID");
assert(
id.kind == ValueKind.STRING,
"Cannot save Deposit entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
);
store.set("Deposit", id.toString(), this);
}
static load(id: string): Deposit | null {
return store.get("Deposit", id) as Deposit | null;
}
get id(): string {
let value = this.get("id");
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
}
get index(): BigInt {
let value = this.get("index");
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
}
get amount(): string {
let value = this.get("amount");
return value.toString();
}
set amount(value: string) {
this.set("amount", Value.fromString(value));
}
get currency(): string {
let value = this.get("currency");
return value.toString();
}
set currency(value: string) {
this.set("currency", Value.fromString(value));
}
get commitment(): Bytes {
let value = this.get("commitment");
return value.toBytes();
}
set commitment(value: Bytes) {
this.set("commitment", Value.fromBytes(value));
}
get timestamp(): BigInt {
let value = this.get("timestamp");
return value.toBigInt();
}
set timestamp(value: BigInt) {
this.set("timestamp", Value.fromBigInt(value));
}
get blockNumber(): BigInt {
let value = this.get("blockNumber");
return value.toBigInt();
}
set blockNumber(value: BigInt) {
this.set("blockNumber", Value.fromBigInt(value));
}
get transactionHash(): Bytes {
let value = this.get("transactionHash");
return value.toBytes();
}
set transactionHash(value: Bytes) {
this.set("transactionHash", Value.fromBytes(value));
}
}
export class Withdrawal extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save Withdrawal entity without an ID");
assert(
id.kind == ValueKind.STRING,
"Cannot save Withdrawal entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
);
store.set("Withdrawal", id.toString(), this);
}
static load(id: string): Withdrawal | null {
return store.get("Withdrawal", id) as Withdrawal | null;
}
get id(): string {
let value = this.get("id");
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
}
get to(): Bytes {
let value = this.get("to");
return value.toBytes();
}
set to(value: Bytes) {
this.set("to", Value.fromBytes(value));
}
get fee(): BigInt {
let value = this.get("fee");
return value.toBigInt();
}
set fee(value: BigInt) {
this.set("fee", Value.fromBigInt(value));
}
get index(): BigInt {
let value = this.get("index");
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
}
get amount(): string {
let value = this.get("amount");
return value.toString();
}
set amount(value: string) {
this.set("amount", Value.fromString(value));
}
get currency(): string {
let value = this.get("currency");
return value.toString();
}
set currency(value: string) {
this.set("currency", Value.fromString(value));
}
get nullifier(): Bytes {
let value = this.get("nullifier");
return value.toBytes();
}
set nullifier(value: Bytes) {
this.set("nullifier", Value.fromBytes(value));
}
get timestamp(): BigInt {
let value = this.get("timestamp");
return value.toBigInt();
}
set timestamp(value: BigInt) {
this.set("timestamp", Value.fromBigInt(value));
}
get blockNumber(): BigInt {
let value = this.get("blockNumber");
return value.toBigInt();
}
set blockNumber(value: BigInt) {
this.set("blockNumber", Value.fromBigInt(value));
}
get transactionHash(): Bytes {
let value = this.get("transactionHash");
return value.toBytes();
}
set transactionHash(value: Bytes) {
this.set("transactionHash", Value.fromBytes(value));
}
}
export class EncryptedNote extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save EncryptedNote entity without an ID");
assert(
id.kind == ValueKind.STRING,
"Cannot save EncryptedNote entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
);
store.set("EncryptedNote", id.toString(), this);
}
static load(id: string): EncryptedNote | null {
return store.get("EncryptedNote", id) as EncryptedNote | null;
}
get id(): string {
let value = this.get("id");
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
}
get index(): BigInt {
let value = this.get("index");
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
}
get blockNumber(): BigInt {
let value = this.get("blockNumber");
return value.toBigInt();
}
set blockNumber(value: BigInt) {
this.set("blockNumber", Value.fromBigInt(value));
}
get encryptedNote(): Bytes {
let value = this.get("encryptedNote");
return value.toBytes();
}
set encryptedNote(value: Bytes) {
this.set("encryptedNote", Value.fromBytes(value));
}
get transactionHash(): Bytes {
let value = this.get("transactionHash");
return value.toBytes();
}
set transactionHash(value: Bytes) {
this.set("transactionHash", Value.fromBytes(value));
}
}
export class NoteAccount extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save NoteAccount entity without an ID");
assert(
id.kind == ValueKind.STRING,
"Cannot save NoteAccount entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
);
store.set("NoteAccount", id.toString(), this);
}
static load(id: string): NoteAccount | null {
return store.get("NoteAccount", id) as NoteAccount | null;
}
get id(): string {
let value = this.get("id");
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
}
get index(): BigInt {
let value = this.get("index");
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
}
get address(): Bytes {
let value = this.get("address");
return value.toBytes();
}
set address(value: Bytes) {
this.set("address", Value.fromBytes(value));
}
get encryptedAccount(): Bytes {
let value = this.get("encryptedAccount");
return value.toBytes();
}
set encryptedAccount(value: Bytes) {
this.set("encryptedAccount", Value.fromBytes(value));
}
}

13
package.json Normal file
View File

@ -0,0 +1,13 @@
{
"name": "sub-graph-proxy",
"license": "UNLICENSED",
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ tornadocash/bsc-tornado-subgraph"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.20.0",
"@graphprotocol/graph-ts": "0.20.0"
}
}

38
schema.graphql Normal file
View File

@ -0,0 +1,38 @@
type Deposit @entity {
id: ID!
index: BigInt!
amount: String!
currency: String!
commitment: Bytes!
timestamp: BigInt!
blockNumber: BigInt!
transactionHash: Bytes!
}
type Withdrawal @entity {
id: ID!
to: Bytes!
fee: BigInt!
index: BigInt!
amount: String!
currency: String!
nullifier: Bytes!
timestamp: BigInt!
blockNumber: BigInt!
transactionHash: Bytes!
}
type EncryptedNote @entity {
id: ID!
index: BigInt!
blockNumber: BigInt!
encryptedNote: Bytes!
transactionHash: Bytes!
}
type NoteAccount @entity {
id: ID!
index: BigInt!
address: Bytes!
encryptedAccount: Bytes!
}

4
src/contractsData.ts Normal file
View File

@ -0,0 +1,4 @@
export let contractMaps = new Map<string, string>();
contractMaps.set('0x0ce22770451a8acad1220d9d1678656b4fae4a1d', 'bnb-0.1');

View File

@ -0,0 +1,12 @@
import { Echo } from '../generated'
import { NoteAccount as NoteAccountEntity } from '../generated/schema'
export function handleEcho(event: Echo): void {
let entity = new NoteAccountEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());
entity.index = event.logIndex;
entity.address = event.params.who;
entity.encryptedAccount = event.params.data;
entity.save();
}

View File

@ -0,0 +1,15 @@
import { EncryptedNote } from '../generated'
import { EncryptedNote as EncryptedNoteEntity } from '../generated/schema'
export function handleEncryptedNote(event: EncryptedNote): void {
let entity = new EncryptedNoteEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());
entity.index = event.logIndex;
entity.blockNumber = event.block.number;
entity.transactionHash = event.transaction.hash;
entity.encryptedNote = event.params.encryptedNote;
if (event.params.encryptedNote.toHexString() != '0x') {
entity.save();
}
}

40
src/mapping-instance.ts Normal file
View File

@ -0,0 +1,40 @@
import { Withdrawal, Deposit } from '../generated'
import { Withdrawal as WithdrawalEntity, Deposit as DepositEntity } from '../generated/schema'
import { contractMaps } from './contractsData'
export function handleWithdrawal(event: Withdrawal): void {
let entity = new WithdrawalEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());
let result = contractMaps.get(event.address.toHexString()).split('-');
entity.amount = result[1];
entity.currency = result[0];
entity.to = event.params.to;
entity.fee = event.params.fee;
entity.index = event.logIndex;
entity.blockNumber = event.block.number;
entity.timestamp = event.block.timestamp;
entity.nullifier = event.params.nullifierHash;
entity.transactionHash = event.transaction.hash;
entity.save();
}
export function handleDeposit(event: Deposit): void {
let entity = new DepositEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString())
let result = contractMaps.get(event.address.toHexString()).split('-');
entity.amount = result[1];
entity.currency = result[0];
entity.index = event.params.leafIndex;
entity.blockNumber = event.block.number;
entity.timestamp = event.block.timestamp;
entity.commitment = event.params.commitment;
entity.transactionHash = event.transaction.hash;
entity.save()
}

67
subgraph.yaml Normal file
View File

@ -0,0 +1,67 @@
specVersion: 0.0.2
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: Proxy
network: bsc
source:
address: "0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7"
abi: Proxy
startBlock: 7941563
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- EncryptedNote
abis:
- name: Proxy
file: ./abis/Proxy.json
eventHandlers:
- event: EncryptedNote(indexed address,bytes)
handler: handleEncryptedNote
file: ./src/mapping-encrypted-note.ts
- kind: ethereum/contract
name: Echoer
network: bsc
source:
address: "0x60eaCBd5535ADB86955A0154E44Aded78F161643"
abi: Echoer
startBlock: 7941563
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- NoteAccount
abis:
- name: Echoer
file: ./abis/Echoer.json
eventHandlers:
- event: Echo(indexed address,bytes)
handler: handleEcho
file: ./src/mapping-echo-account.ts
- kind: ethereum/contract
name: Instance
network: bsc
source:
address: "0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d"
abi: Instance
startBlock: 7941563
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- Deposit
- Withdrawal
abis:
- name: Instance
file: ./abis/Instance.json
eventHandlers:
- event: Deposit(indexed bytes32,uint32,uint256)
handler: handleDeposit
- event: Withdrawal(address,bytes32,indexed address,uint256)
handler: handleWithdrawal
file: ./src/mapping-instance.ts

3002
yarn.lock Normal file

File diff suppressed because it is too large Load Diff