Initial commit from Create Eth App
This commit is contained in:
76
packages/subgraph/README.md
Normal file
76
packages/subgraph/README.md
Normal file
@@ -0,0 +1,76 @@
|
||||
## @my-app/subgraph
|
||||
|
||||
The Graph is a tool for for indexing events emitted on the Ethereum blockchain. It provides you with an easy-to-use GraphQL API.
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### Subgraph
|
||||
|
||||
#### `yarn codegen`
|
||||
|
||||
Generates AssemblyScript types for smart contract ABIs and the subgraph schema.
|
||||
|
||||
#### `yarn build`
|
||||
|
||||
Compiles the subgraph to WebAssembly.
|
||||
|
||||
#### `yarn auth`
|
||||
|
||||
Before deploying your subgraph, you need to sign up on the
|
||||
[Graph Explorer](https://thegraph.com/explorer/). There, you will be given an access token. Drop it in the command
|
||||
below:
|
||||
|
||||
```sh
|
||||
GRAPH_ACCESS_TOKEN=your-access-token-here yarn subgraph:auth
|
||||
```
|
||||
|
||||
#### `yarn deploy`
|
||||
|
||||
Deploys the subgraph to the official Graph Node.<br/>
|
||||
|
||||
Replace `paulrberg/create-eth-app` in the package.json script with your subgraph's name.
|
||||
|
||||
You may also want to [read more about the hosted service](https://thegraph.com/docs/quick-start#hosted-service).
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn The Graph, check out the [The Graph documentation](https://thegraph.com/docs).
|
||||
|
||||
---
|
||||
|
||||
1. Generate types
|
||||
2. Build distributable files
|
||||
3. Deploy to the remote API
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [The Graph documentation](https://thegraph.com/docs).<br/>
|
||||
|
||||
Also consider joining [The Graph Discord server](https://discord.gg/vtvv7FP), where you can seek out help.
|
||||
|
||||
## Common Errors
|
||||
|
||||
### Failed to Compile
|
||||
|
||||
> ✖ Failed to compile subgraph: Failed to compile data source mapping: Import file 'src/types/schema.ts' not found.
|
||||
> Error: Failed to compile data source mapping: Import file 'src/types/schema.ts' not found.
|
||||
|
||||
Run the `yarn subgraph` and this error will go away.
|
||||
|
||||
### No Access Token
|
||||
|
||||
> ✖ No access token provided
|
||||
|
||||
Make sure that you followed the instructions listed above for [yarn auth](#yarn-auth).
|
||||
|
||||
### Failed to Deploy
|
||||
|
||||
> ✖ Failed to deploy to Graph node https://api.thegraph.com/deploy/: Invalid account name or access token
|
||||
|
||||
Make sure that you:
|
||||
|
||||
1. Signed up on the [Graph Explorer](https://thegraph.com/explorer)
|
||||
2. Followed the instructions listed above for [yarn auth](#yarn-auth)
|
||||
3. Replaced `paulrberg/create-eth-app` with your subgraph's name
|
||||
15
packages/subgraph/package.json
Normal file
15
packages/subgraph/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@my-app/subgraph",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@graphprotocol/graph-cli": "0.28.0",
|
||||
"@graphprotocol/graph-ts": "0.26.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"auth": "graph auth https://api.thegraph.com/ $GRAPH_ACCESS_TOKEN",
|
||||
"build": "graph build",
|
||||
"codegen": "graph codegen --output-dir src/types/",
|
||||
"deploy": "graph deploy paulrberg/create-eth-app --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/"
|
||||
}
|
||||
}
|
||||
13
packages/subgraph/schema.graphql
Normal file
13
packages/subgraph/schema.graphql
Normal file
@@ -0,0 +1,13 @@
|
||||
type Token @entity {
|
||||
id: ID!
|
||||
decimals: Int
|
||||
name: String
|
||||
symbol: String
|
||||
}
|
||||
|
||||
type Transfer @entity {
|
||||
id: ID!
|
||||
from: String!
|
||||
to: String!
|
||||
value: BigInt!
|
||||
}
|
||||
21
packages/subgraph/src/mappings/tokens.ts
Normal file
21
packages/subgraph/src/mappings/tokens.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Token } from "../types/schema";
|
||||
|
||||
export function addToken(address: string): void {
|
||||
let token: Token | null = Token.load(address);
|
||||
if (token != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
token = new Token(address);
|
||||
if (address == "0xa6dF0C88916f3e2831A329CE46566dDfBe9E74b7") {
|
||||
token.decimals = 18;
|
||||
token.name = "CeaErc20";
|
||||
token.symbol = "CEAERC20";
|
||||
} else {
|
||||
token.decimals = 0;
|
||||
token.name = null;
|
||||
token.symbol = null;
|
||||
}
|
||||
|
||||
token.save();
|
||||
}
|
||||
19
packages/subgraph/src/mappings/transfers.ts
Normal file
19
packages/subgraph/src/mappings/transfers.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Address } from "@graphprotocol/graph-ts";
|
||||
|
||||
import { Transfer as TransferEvent } from "../types/CeaErc20/erc20";
|
||||
import { Transfer } from "../types/schema";
|
||||
import { addToken } from "./tokens";
|
||||
|
||||
export function handleTransfer(event: TransferEvent): void {
|
||||
let transactionHash: string = event.transaction.hash.toHex();
|
||||
let transfer = new Transfer(transactionHash);
|
||||
transfer.from = event.params.from.toHex();
|
||||
transfer.to = event.params.to.toHex();
|
||||
transfer.value = event.params.value;
|
||||
transfer.save();
|
||||
|
||||
let to: Address | null = event.transaction.to;
|
||||
if (to) {
|
||||
addToken(to.toHex());
|
||||
}
|
||||
}
|
||||
26
packages/subgraph/subgraph.yaml
Normal file
26
packages/subgraph/subgraph.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
specVersion: 0.0.4
|
||||
description: Subgraph that indexes the blockchain data
|
||||
repository: https://github.com/sablierhq/sablier-subgraph
|
||||
schema:
|
||||
file: ./schema.graphql
|
||||
dataSources:
|
||||
- kind: ethereum/contract
|
||||
name: CeaErc20
|
||||
network: mainnet
|
||||
source:
|
||||
abi: erc20
|
||||
address: "0xa6dF0C88916f3e2831A329CE46566dDfBe9E74b7"
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
apiVersion: 0.0.6
|
||||
abis:
|
||||
- name: erc20
|
||||
file: ../contracts/src/abis/erc20.json
|
||||
entities:
|
||||
- Token
|
||||
- Transfer
|
||||
eventHandlers:
|
||||
- event: Transfer(indexed address,indexed address,uint256)
|
||||
handler: handleTransfer
|
||||
file: ./src/mappings/transfers.ts
|
||||
language: wasm/assemblyscript
|
||||
Reference in New Issue
Block a user