mirror of
https://github.com/tornadocash/landing-subgraph.git
synced 2024-11-22 01:36:52 +01:00
Initial commit
This commit is contained in:
commit
0406c94953
381
abis/Contract.json
Normal file
381
abis/Contract.json
Normal file
@ -0,0 +1,381 @@
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "internalType": "address", "name": "_newOperator", "type": "address" }
|
||||
],
|
||||
"name": "changeOperator",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
|
||||
"name": "nullifierHashes",
|
||||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "internalType": "bytes", "name": "_proof", "type": "bytes" },
|
||||
{ "internalType": "bytes32", "name": "_root", "type": "bytes32" },
|
||||
{
|
||||
"internalType": "bytes32",
|
||||
"name": "_nullifierHash",
|
||||
"type": "bytes32"
|
||||
},
|
||||
{
|
||||
"internalType": "address payable",
|
||||
"name": "_recipient",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address payable",
|
||||
"name": "_relayer",
|
||||
"type": "address"
|
||||
},
|
||||
{ "internalType": "uint256", "name": "_fee", "type": "uint256" },
|
||||
{ "internalType": "uint256", "name": "_refund", "type": "uint256" }
|
||||
],
|
||||
"name": "withdraw",
|
||||
"outputs": [],
|
||||
"payable": true,
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "verifier",
|
||||
"outputs": [
|
||||
{ "internalType": "contract IVerifier", "name": "", "type": "address" }
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{ "internalType": "bytes32", "name": "_left", "type": "bytes32" },
|
||||
{ "internalType": "bytes32", "name": "_right", "type": "bytes32" }
|
||||
],
|
||||
"name": "hashLeftRight",
|
||||
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "FIELD_SIZE",
|
||||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "levels",
|
||||
"outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "operator",
|
||||
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes32[]",
|
||||
"name": "_filledSubtrees",
|
||||
"type": "bytes32[]"
|
||||
},
|
||||
{ "internalType": "bytes32", "name": "_root", "type": "bytes32" }
|
||||
],
|
||||
"name": "initializeTreeForMigration",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{ "internalType": "bytes32", "name": "_root", "type": "bytes32" }
|
||||
],
|
||||
"name": "isKnownRoot",
|
||||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
|
||||
"name": "commitments",
|
||||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [],
|
||||
"name": "finishMigration",
|
||||
"outputs": [],
|
||||
"payable": true,
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "denomination",
|
||||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "currentRootIndex",
|
||||
"outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes32[]",
|
||||
"name": "_commitments",
|
||||
"type": "bytes32[]"
|
||||
},
|
||||
{
|
||||
"internalType": "bytes32[]",
|
||||
"name": "_nullifierHashes",
|
||||
"type": "bytes32[]"
|
||||
}
|
||||
],
|
||||
"name": "migrateState",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "internalType": "address", "name": "_newVerifier", "type": "address" }
|
||||
],
|
||||
"name": "updateVerifier",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes32[]",
|
||||
"name": "_nullifierHashes",
|
||||
"type": "bytes32[]"
|
||||
}
|
||||
],
|
||||
"name": "isSpentArray",
|
||||
"outputs": [
|
||||
{ "internalType": "bool[]", "name": "spent", "type": "bool[]" }
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "isMigrated",
|
||||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "internalType": "bytes32", "name": "_commitment", "type": "bytes32" }
|
||||
],
|
||||
"name": "deposit",
|
||||
"outputs": [],
|
||||
"payable": true,
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "getLastRoot",
|
||||
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
||||
"name": "roots",
|
||||
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "ROOT_HISTORY_SIZE",
|
||||
"outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{ "internalType": "bytes32", "name": "_nullifierHash", "type": "bytes32" }
|
||||
],
|
||||
"name": "isSpent",
|
||||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
||||
"name": "zeros",
|
||||
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "ZERO_VALUE",
|
||||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
||||
"name": "filledSubtrees",
|
||||
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "nextIndex",
|
||||
"outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "contract IVerifier",
|
||||
"name": "_verifier",
|
||||
"type": "address"
|
||||
},
|
||||
{ "internalType": "uint256", "name": "_denomination", "type": "uint256" },
|
||||
{
|
||||
"internalType": "uint32",
|
||||
"name": "_merkleTreeHeight",
|
||||
"type": "uint32"
|
||||
},
|
||||
{ "internalType": "address", "name": "_operator", "type": "address" }
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
16
package.json
Normal file
16
package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "test",
|
||||
"license": "UNLICENSED",
|
||||
"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"
|
||||
},
|
||||
"dependencies": {
|
||||
"@graphprotocol/graph-cli": "0.20.0",
|
||||
"@graphprotocol/graph-ts": "0.20.0"
|
||||
}
|
||||
}
|
6
schema.graphql
Normal file
6
schema.graphql
Normal file
@ -0,0 +1,6 @@
|
||||
type ExampleEntity @entity {
|
||||
id: ID!
|
||||
count: BigInt!
|
||||
commitment: Bytes! # bytes32
|
||||
leafIndex: BigInt! # uint32
|
||||
}
|
66
src/mapping.ts
Normal file
66
src/mapping.ts
Normal file
@ -0,0 +1,66 @@
|
||||
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
subgraph.yaml
Normal file
26
subgraph.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
specVersion: 0.0.1
|
||||
schema:
|
||||
file: ./schema.graphql
|
||||
dataSources:
|
||||
- kind: ethereum/contract
|
||||
name: Contract
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x12D66f87A04A9E220743712cE6d9bB1B5616B8Fc"
|
||||
abi: Contract
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
apiVersion: 0.0.2
|
||||
language: wasm/assemblyscript
|
||||
entities:
|
||||
- Deposit
|
||||
- Withdrawal
|
||||
abis:
|
||||
- name: Contract
|
||||
file: ./abis/Contract.json
|
||||
eventHandlers:
|
||||
- event: Deposit(indexed bytes32,uint32,uint256)
|
||||
handler: handleDeposit
|
||||
- event: Withdrawal(address,bytes32,indexed address,uint256)
|
||||
handler: handleWithdrawal
|
||||
file: ./src/mapping.ts
|
Loading…
Reference in New Issue
Block a user