-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indexers v2 #132
Indexers v2 #132
Changes from 8 commits
c56719d
5efd639
5ef68ea
1103017
4811eed
8676c18
7907660
412b0d5
d9078aa
ca9d08d
7275dc9
cde7a83
3623f3c
3136887
a786170
226f8a7
992ea2b
91ab6cf
b7bb3ca
ea8f205
7889047
2976d5a
69d2ec6
978b140
981affb
ef9fb76
b18a47e
d3eea6f
fe8a67c
2eeaa5d
1bd0517
5f1190a
3646184
fbe4130
b0dd1d3
2f4b52d
bbeef8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM node:16-alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json ./ | ||
COPY requirements.txt . | ||
|
||
RUN apk add --no-cache python3 py3-pip | ||
RUN apk add --no-cache build-base && npm ci && apk del build-base | ||
|
||
COPY . . | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
ENTRYPOINT ["sh", "-c", "python3 main.py --network_name \"$NETWORK_NAME\" --rpc_endpoint \"$RPC_ENDPOINT\" && npm run generate:processor && npm run build && (npm run generate:migration || true) && npm run start"] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"$schema": "https://cdn.subsquid.io/schemas/commands.json", | ||
"commands": { | ||
"clean": { | ||
"description": "delete all build artifacts", | ||
"cmd": ["npx", "--yes", "rimraf", "lib"] | ||
}, | ||
"generate": { | ||
"description": "Generate a squid from an ABI file", | ||
"cmd": ["squid-gen-abi"] | ||
}, | ||
"squid-gen-abi": { | ||
"description": "Generate a squid from an ABI file", | ||
"cmd": ["squid-gen-abi"], | ||
"hidden": true | ||
}, | ||
"build": { | ||
"description": "Build the squid project", | ||
"deps": ["clean"], | ||
"cmd": ["tsc"] | ||
}, | ||
"up": { | ||
"description": "Start a PG database", | ||
"cmd": ["docker-compose", "up", "-d"] | ||
}, | ||
"down": { | ||
"description": "Drop a PG database", | ||
"cmd": ["docker-compose", "down"] | ||
}, | ||
"migration:apply": { | ||
"description": "Apply the DB migrations", | ||
"cmd": ["squid-typeorm-migration", "apply"] | ||
}, | ||
"migration:generate": { | ||
"description": "Generate a DB migration matching the TypeORM entities", | ||
"deps": ["build", "migration:clean"], | ||
"cmd": ["squid-typeorm-migration", "generate"], | ||
}, | ||
"migration:clean": { | ||
"description": "Clean the migrations folder", | ||
"cmd": ["npx", "--yes", "rimraf", "./db/migrations"], | ||
}, | ||
"migration": { | ||
"deps": ["build"], | ||
"cmd": ["squid-typeorm-migration", "generate"], | ||
"hidden": true | ||
}, | ||
"codegen": { | ||
"description": "Generate TypeORM entities from the schema file", | ||
"cmd": ["squid-typeorm-codegen"] | ||
}, | ||
"typegen": { | ||
"description": "Generate data access classes for an ABI file(s) in the ./abi folder", | ||
"cmd": ["squid-evm-typegen", "./src/abi", {"glob": "./abi/*.json"}, "--multicall"] | ||
}, | ||
"process": { | ||
"description": "Load .env and start the squid processor", | ||
"deps": ["build", "migration:apply"], | ||
"cmd": ["node", "--require=dotenv/config", "lib/main.js"] | ||
}, | ||
"process:prod": { | ||
"description": "Start the squid processor", | ||
"deps": ["migration:apply"], | ||
"cmd": ["node", "lib/main.js"], | ||
"hidden": true | ||
}, | ||
"serve": { | ||
"description": "Start the GraphQL API server", | ||
"cmd": ["squid-graphql-server"] | ||
}, | ||
"serve:prod": { | ||
"description": "Start the GraphQL API server with caching and limits", | ||
"cmd": ["squid-graphql-server", | ||
"--dumb-cache", "in-memory", | ||
"--dumb-cache-ttl", "1000", | ||
"--dumb-cache-size", "100", | ||
"--dumb-cache-max-age", "1000" ] | ||
}, | ||
"check-updates": { | ||
"cmd": ["npx", "--yes", "npm-check-updates", "--filter=/subsquid/", "--upgrade"], | ||
"hidden": true | ||
}, | ||
"bump": { | ||
"description": "Bump @subsquid packages to the latest versions", | ||
"deps": ["check-updates"], | ||
"cmd": ["npm", "i", "-f"] | ||
}, | ||
"open": { | ||
"description": "Open a local browser window", | ||
"cmd": ["npx", "--yes", "opener"] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import json | ||
import sys | ||
import os | ||
import argparse | ||
import yaml | ||
from synthetix import Synthetix | ||
|
||
|
||
def save_abi(abi, contract_name): | ||
os.makedirs("abi", exist_ok=True) | ||
with open(f"abi/{contract_name}.json", "w") as file: | ||
json.dump(abi, file, indent=2) | ||
|
||
|
||
def create_squidgen_config(rpc_url, archive_url, contracts_info): | ||
config = { | ||
"archive": archive_url, | ||
"finalityConfirmation": 1, | ||
"chain": {"url": rpc_url, "rateLimit": 10}, | ||
"target": {"type": "postgres"}, | ||
"contracts": [], | ||
} | ||
|
||
for contract in contracts_info: | ||
name = contract["name"] | ||
address = contract["address"] | ||
contract_config = { | ||
"name": name, | ||
"address": address, | ||
"abi": f"./abi/{name}.json", | ||
"events": True, | ||
"functions": False, | ||
} | ||
config["contracts"].append(contract_config) | ||
|
||
return config | ||
|
||
|
||
def create_squid_config(network_name): | ||
return { | ||
"manifestVersion": "subsquid.io/v0.1", | ||
"name": network_name, | ||
"version": 1, | ||
"description": "A squid indexer generated from an ABI template", | ||
"build": None, | ||
"deploy": { | ||
"addons": {"postgres": None}, | ||
"processor": {"cmd": ["node", "lib/main"]}, | ||
"api": { | ||
"cmd": [ | ||
"npx", | ||
"squid-graphql-server", | ||
"--dumb-cache", | ||
"in-memory", | ||
"--dumb-cache-ttl", | ||
"1000", | ||
"--dumb-cache-size", | ||
"100", | ||
"--dumb-cache-max-age", | ||
"1000", | ||
] | ||
}, | ||
}, | ||
} | ||
|
||
|
||
def write_yaml(config, filename): | ||
with open(filename, "w") as file: | ||
yaml.dump(config, file, default_flow_style=False) | ||
|
||
|
||
def load_network_config(path): | ||
with open(f"{path}/network_config.yaml", "r") as file: | ||
return yaml.safe_load(file) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description="Generate Squid configuration files for a given network" | ||
) | ||
parser.add_argument("--network_name", type=str, help="Network name", required=True) | ||
parser.add_argument("--rpc_endpoint", type=str, help="RPC URL", required=True) | ||
args = parser.parse_args() | ||
|
||
network_name = args.network_name | ||
path = f"networks/{network_name}" | ||
network_config = load_network_config(path)[network_name] | ||
|
||
if not network_config: | ||
print(f"Network '{network_name}' not found in {path}/network_config.yaml") | ||
sys.exit(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using |
||
|
||
rpc_endpoint = args.rpc_endpoint | ||
if not rpc_endpoint: | ||
print("RPC_ENDPOINT environment variable is not set") | ||
sys.exit(1) | ||
archive_url = network_config["archive_url"] | ||
|
||
contracts = [] | ||
|
||
if "contracts_from_sdk" in network_config: | ||
contracts_from_sdk = network_config["contracts_from_sdk"] | ||
|
||
if "cannon_config" in network_config: | ||
snx = Synthetix( | ||
provider_rpc=rpc_endpoint, | ||
network_id=network_config["network_id"], | ||
cannon_config=network_config["cannon_config"], | ||
) | ||
else: | ||
snx = Synthetix( | ||
provider_rpc=rpc_endpoint, | ||
network_id=network_config["network_id"], | ||
) | ||
|
||
for contract in contracts_from_sdk: | ||
name = contract["name"] | ||
package = contract["package"] | ||
contract_data = snx.contracts[package][name] | ||
if name == "buyback_snx": | ||
name = "BuybackSnx" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? I know the contract is named something weird, but we don't want to handle that logic here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcus-snx still need to fix this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah somehow I managed to discard this change. Thanks for the reminder! |
||
save_abi(contract_data["abi"], name) | ||
contracts.append({"name": name, "address": contract_data["address"]}) | ||
|
||
if "contracts_from_abi" in network_config: | ||
contracts_from_abi = network_config["contracts_from_abi"] | ||
|
||
for contract in contracts_from_abi: | ||
name = contract["name"] | ||
with open(f"{path}/abi/{name}.json", "r") as file: | ||
contract_abi = json.load(file) | ||
save_abi(contract_abi, name) | ||
contracts.append({"name": name, "address": contract["address"]}) | ||
|
||
squidgen_config = create_squidgen_config(rpc_endpoint, archive_url, contracts) | ||
write_yaml(squidgen_config, "squidgen.yaml") | ||
|
||
squid_config = create_squid_config(args.network_name) | ||
write_yaml(squid_config, "squid.yaml") | ||
|
||
print( | ||
f"squidgen.yaml, squid.yaml, and ABI files have been generated for {args.network_name}" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
arbitrum_mainnet: | ||
archive_url: "https://v2.archive.subsquid.io/network/arbitrum-one" | ||
contracts: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This format is different from the base one |
||
- ["CoreProxy", "system"] | ||
- ["AccountProxy", "system"] | ||
- ["SpotMarketProxy", "spotFactory"] | ||
- ["PerpsMarketProxy", "perpsFactory"] | ||
- ["PerpsAccountProxy", "perpsFactory"] | ||
network_id: 42161 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can simplify this entrypoint, potentially just make a shell script that calls this stuff in order. It would simplify the docker compose commands if we can just call a script with configurations