Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ build/
node_modules/
src/types/
.DS_STORE
yarn-error.log
yarn-error.log
subgraph.yaml
/generated
61 changes: 53 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
# Subgraph for Ethereum block data
# Blocks Subgraph

This subgraph indexes all block data on the [Arbitrum One mainnet beta network](https://offchain.medium.com/introducing-arbitrum-one-our-mainet-beta-ed0e9b63b435).
A subgraph that indexes block data for EVM networks.

Every block is handled by one mapping ```handleBlock```
## Setup

##### Note
```bash
yarn install
```

The contract `ConverterRegistryContract` found in ABIs and subgraph.yaml is just a dummy contract used to pass formatting checks. Each block is handled automatically regardless of the logic in this contract.

##
Subgraph endpoint: [https://thegraph.com/explorer/subgraph/ianlapham/arbitrum-one-blocks](https://thegraph.com/explorer/subgraph/ianlapham/arbitrum-one-blocks).
## Deploy Workflow

### 1. Generate subgraph manifest for your network

```bash
yarn generate <network>
```

**Supported networks:**
- `mainnet`
- `arbitrum-one`
- `optimism`
- `polygon`
- `base`
- etc.

### 2. Build the subgraph

```bash
yarn build
```

### 3. Deploy

```bash
yarn deploy --studio <subgraph-name>
# or
yarn deploy --product hosted-service <github-user>/<subgraph-name>
```

## Example: Deploy to Arbitrum One

```bash
yarn generate arbitrum-one
yarn build
yarn deploy --studio arbitrum-one-blocks
```

## Architecture

- `subgraph.template.yaml` - Template with `{{network}}` placeholder
- `scripts/generate-subgraph.ts` - Generates `subgraph.yaml` for a specific network
- `src/mappings/blocks.ts` - Block handler that indexes all block data

### Note

The `ConverterRegistryContract` in ABIs and subgraph.yaml is a dummy contract used to pass formatting checks. Each block is handled automatically via the `blockHandlers` configuration.
36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
"repository": "https://github.com/graphprotocol/uniswap-v3-subgraph",
"license": "GPL-3.0-or-later",
"scripts": {
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"create-local": "graph create ianlapham/uniswap-v3 --node http://127.0.0.1:8020",
"deploy-local": "graph deploy ianlapham/uniswap-v3 --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy ianlapham/arbitrum-one-blocks --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy-dev": "graph deploy sommelier/uniswap-v3 --ipfs http://35.197.14.14:5000/ --node http://35.197.14.14:8020/ --debug",
"deploy-staging": "graph deploy $THE_GRAPH_GITHUB_USER/$THE_GRAPH_SUBGRAPH_NAME /Uniswap --ipfs https://api.staging.thegraph.com/ipfs/ --node https://api.staging.thegraph.com/deploy/",
"watch-local": "graph deploy ianlapham/uniswap-v3 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
"generate": "npx tsx scripts/generate-subgraph.ts",
"build": "graph codegen && graph build",
"deploy": "graph deploy"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.51.1",
"@graphprotocol/graph-ts": "^0.31.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^6.2.2",
"eslint-config-prettier": "^6.1.0",
"prettier": "^1.18.2",
"typescript": "^3.5.2"
"tsx": "^4.19.0",
"@graphprotocol/graph-cli": "^0.98.1",
"@graphprotocol/graph-ts": "^0.38.2",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.3.0",
"typescript": "^5.5.0"
},
"resolutions": {
"axios": "^1.7.8",
"ejs": "^3.1.10",
"semver": "^7.6.3",
"cross-spawn": "^7.0.6",
"js-yaml": "^4.1.1",
"glob": "^11.1.0"
}
}
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Block @entity {
type Block @entity(immutable: true) {
id: ID!
number: BigInt!
timestamp: BigInt!
Expand Down
20 changes: 20 additions & 0 deletions scripts/generate-subgraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as fs from 'fs';
import * as path from 'path';

const network = process.argv[2];

if (!network) {
console.error('Usage: npx tsx scripts/generate-subgraph.ts <network>');
console.error('Example: npx tsx scripts/generate-subgraph.ts arbitrum-one');
process.exit(1);
}

const templatePath = path.join(__dirname, '..', 'subgraph.template.yaml');
const outputPath = path.join(__dirname, '..', 'subgraph.yaml');

const template = fs.readFileSync(templatePath, 'utf8');
const output = template.replace(/\{\{network\}\}/g, network);

fs.writeFileSync(outputPath, output);
console.log(`Generated subgraph.yaml for network: ${network}`);

2 changes: 1 addition & 1 deletion src/mappings/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethereum } from '@graphprotocol/graph-ts'
import { Block } from '../types/schema'
import { Block } from '../../generated/schema'

export function handleBlock(block: ethereum.Block): void {
let id = block.hash.toHex()
Expand Down
7 changes: 4 additions & 3 deletions subgraph.yaml → subgraph.template.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
specVersion: 0.0.2
description: Indexing all Arbitrum One Block data
description: Indexing all {{network}} Block data
repository: https://github.com/blocklytics/ethereum-blocks
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: ConverterRegistryContract
network: arbitrum-one
network: {{network}}
source:
address: '0x0ddff327ddf7fe838e3e63d02001ef23ad1ede8e'
abi: ConverterRegistryContract
startBlock: 1
mapping:
kind: ethereum/events
apiVersion: 0.0.4
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- ConverterAddition
Expand All @@ -23,3 +23,4 @@ dataSources:
blockHandlers:
- handler: handleBlock
file: ./src/mappings/blocks.ts

Loading