Skip to content

Commit

Permalink
Added Dymension Example
Browse files Browse the repository at this point in the history
  • Loading branch information
bgodlin committed Nov 19, 2023
1 parent 39487e1 commit a571888
Show file tree
Hide file tree
Showing 48 changed files with 2,107 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Dymension/dymension-starter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Node artifact files
node_modules/
dist/

# lock files
yarn.lock
package-lock.json

# Compiled Java class files
*.class

# Compiled Python bytecode
*.py[cod]

# Log files
*.log

# Package files
*.jar

# Generated files
target/
dist/
src/types
project.yaml

# JetBrains IDE
.idea/

# Unit test reports
TEST*.xml

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv

.data
dist
79 changes: 79 additions & 0 deletions Dymension/dymension-starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# SubQuery - Example Project for Dymension

[SubQuery](https://subquery.network) is a fast, flexible, and reliable open-source data indexer that provides you with custom APIs for your web3 project across all of our supported networks. To learn about how to get started with SubQuery, [visit our docs](https://academy.subquery.network).

**This SubQuery project indexes all transfer events on Dymension**

## Start

First, install SubQuery CLI globally on your terminal by using NPM `npm install -g @subql/cli`

You can either clone this GitHub repo, or use the `subql` CLI to bootstrap a clean project in the network of your choosing by running `subql init` and following the prompts.

Don't forget to install dependencies with `npm install` or `yarn install`!

## Editing your SubQuery project

Although this is a working example SubQuery project, you can edit the SubQuery project by changing the following files:

- The project manifest in `project.ts` defines the key project configuration and mapping handler filters
- The GraphQL Schema (`schema.graphql`) defines the shape of the resulting data that you are using SubQuery to index
- The Mapping functions in `src/mappings/` directory are typescript functions that handle transformation logic

SubQuery supports various layer-1 blockchain networks and provides [dedicated quick start guides](https://academy.subquery.network/quickstart/quickstart.html) as well as [detailed technical documentation](https://academy.subquery.network/build/introduction.html) for each of them.

## Run your project

_If you get stuck, find out how to get help below._

The simplest way to run your project is by running `yarn dev` or `npm run-script dev`. This does all of the following:

1. `yarn codegen` - Generates types from the GraphQL schema definition and contract ABIs and saves them in the `/src/types` directory. This must be done after each change to the `schema.graphql` file or the contract ABIs
2. `yarn build` - Builds and packages the SubQuery project into the `/dist` directory
3. `docker-compose pull && docker-compose up` - Runs a Docker container with an indexer, PostgeSQL DB, and a query service. This requires [Docker to be installed](https://docs.docker.com/engine/install) and running locally. The configuration for this container is set from your `docker-compose.yml`

You can observe the three services start, and once all are running (it may take a few minutes on your first start), please open your browser and head to [http://localhost:3000](http://localhost:3000) - you should see a GraphQL playground showing with the schemas ready to query. [Read the docs for more information](https://academy.subquery.network/run_publish/run.html) or [explore the possible service configuration for running SubQuery](https://academy.subquery.network/run_publish/references.html).

## Query your project

For this project, you can try to query with the following GraphQL code to get a taste of how it works.

```graphql
{
query {
transfers(first: 5) {
nodes {
id
blockHeight
txHash
recipient
sender
amount
}
}
}
}
```

You can explore the different possible queries and entities to help you with GraphQL using the documentation draw on the right.

## Publish your project

SubQuery is open-source, meaning you have the freedom to run it in the following three ways:

- Locally on your own computer (or a cloud provider of your choosing), [view the instructions on how to run SubQuery Locally](https://academy.subquery.network/run_publish/run.html)
- By publishing it to our enterprise-level [Managed Service](https://managedservice.subquery.network), where we'll host your SubQuery project in production ready services for mission critical data with zero-downtime blue/green deployments. We even have a generous free tier. [Find out how](https://academy.subquery.network/run_publish/publish.html)
- [Coming Soon] By publishing it to the decentralised [SubQuery Network](https://subquery.network/network), the most open, performant, reliable, and scalable data service for dApp developers. The SubQuery Network indexes and services data to the global community in an incentivised and verifiable way

## What Next?

Take a look at some of our advanced features to take your project to the next level!

- [**Multi-chain indexing support**](https://academy.subquery.network/build/multi-chain.html) - SubQuery allows you to index data from across different layer-1 networks into the same database, this allows you to query a single endpoint to get data for all supported networks.
- [**Dynamic Data Sources**](https://academy.subquery.network/build/dynamicdatasources.html) - When you want to index factory contracts, for example on a DEX or generative NFT project.
- [**Project Optimisation Advice**](https://academy.subquery.network/build/optimisation.html) - Some common tips on how to tweak your project to maximise performance.
- [**GraphQL Subscriptions**](https://academy.subquery.network/run_publish/subscription.html) - Build more reactive front end applications that subscribe to changes in your SubQuery project.

## Need Help?

The fastest way to get support is by [searching our documentation](https://academy.subquery.network), or by [joining our discord](https://discord.com/invite/subquery) and messaging us in the `#technical-support` channel.
66 changes: 66 additions & 0 deletions Dymension/dymension-starter/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: "3"

services:
postgres:
build:
context: .
dockerfile: ./docker/pg-Dockerfile
ports:
- 5432:5432
volumes:
- .data/postgres:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

subquery-node:
image: subquerynetwork/subql-node-cosmos:latest
depends_on:
"postgres":
condition: service_healthy
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
volumes:
- ./:/app
command:
- ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests
- -f=/app
- --db-schema=app
- --workers=4
- --batch-size=30
- --unfinalized-blocks=true
healthcheck:
test: ["CMD", "curl", "-f", "http://subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

graphql-engine:
image: onfinality/subql-query:latest
ports:
- 3000:3000
depends_on:
"postgres":
condition: service_healthy
"subquery-node":
condition: service_healthy
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
command:
- --name=app
- --playground
- --indexer=http://subquery-node:3000
5 changes: 5 additions & 0 deletions Dymension/dymension-starter/docker/load-extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<EOF
CREATE EXTENSION IF NOT EXISTS btree_gist;
EOF
12 changes: 12 additions & 0 deletions Dymension/dymension-starter/docker/pg-Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM postgres:16-alpine

# Variables needed at runtime to configure postgres and run the initdb scripts
ENV POSTGRES_DB 'postgres'
ENV POSTGRES_USER 'postgres'
ENV POSTGRES_PASSWORD 'postgres'

# Copy in the load-extensions script
COPY docker/load-extensions.sh /docker-entrypoint-initdb.d/

# Convert line endings to LF
RUN sed -i 's/\r$//' /docker-entrypoint-initdb.d/load-extensions.sh && chmod +x /docker-entrypoint-initdb.d/load-extensions.sh
37 changes: 37 additions & 0 deletions Dymension/dymension-starter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "dymension",
"version": "0.0.1",
"description": "desc",
"main": "dist/index.js",
"scripts": {
"build": "subql build",
"codegen": "subql codegen",
"start:docker": "docker-compose pull && docker-compose up --remove-orphans",
"dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
"prepack": "rm -rf dist && npm run build",
"test": "subql build && subql-node-cosmos test"
},
"homepage": "https://github.com/subquery/cosmos-subql-starter",
"repository": "github:subquery/cosmos-subql-starter",
"files": [
"dist",
"schema.graphql",
"project.yaml"
],
"author": "tony",
"license": "MIT",
"devDependencies": {
"@cosmjs/stargate": "^0.28.9",
"@subql/cli": "latest",
"@subql/testing": "latest",
"@subql/node-cosmos": "latest",
"typescript": "^5.2.2"
},
"dependencies": {
"@subql/types-cosmos": "latest",
"@types/node": "^17.0.21",
"pino": "^7.8.0",
"ts-proto": "^1.112.1",
"tslib": "^2.3.1"
}
}
84 changes: 84 additions & 0 deletions Dymension/dymension-starter/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {
CosmosDatasourceKind,
CosmosHandlerKind,
CosmosProject,
} from "@subql/types-cosmos";

// Can expand the Datasource processor types via the genreic param
const project: CosmosProject = {
specVersion: "1.0.0",
version: "0.0.1",
name: "dymension-starter",
description:
"This project can be use as a starting point for developing your Cosmos Dymension based SubQuery project",
runner: {
node: {
name: "@subql/node-cosmos",
version: ">=3.0.0",
},
query: {
name: "@subql/query",
version: "*",
},
},
schema: {
file: "./schema.graphql",
},
network: {
chainId: "froopyland_100-1",
/**
* These endpoint(s) should be non-pruned archive nodes
* Public nodes may be rate limited, which can affect indexing speed
* When developing your project we suggest getting a private API key
* We suggest providing an array of endpoints for increased speed and reliability
*/
endpoint: ["https://rpc-t.dymension.nodestake.top/"],
chaintypes: new Map([
[
"cosmos.slashing.v1beta1",
{
file: "./proto/cosmos/slashing/v1beta1/tx.proto",
messages: ["MsgUnjail"],
},
],
[
"cosmos.gov.v1beta1",
{
file: "./proto/cosmos/gov/v1beta1/tx.proto",
messages: ["MsgVoteWeighted"],
},
],
[
"cosmos.gov.v1beta1.gov",
{
file: "./proto/cosmos/gov/v1beta1/gov.proto",
messages: ["WeightedVoteOption"],
},
],
]),
},
dataSources: [
{
kind: CosmosDatasourceKind.Runtime,
startBlock: 1326903,
mapping: {
file: "./dist/index.js",
handlers: [
{
handler: "handleEvent",
kind: CosmosHandlerKind.Event,
filter: {
type: "transfer",
messageFilter: {
type: "/cosmos.bank.v1beta1.MsgSend",
},
},
},
],
},
},
],
};

// Must set default to the project instance
export default project;
8 changes: 8 additions & 0 deletions Dymension/dymension-starter/proto/buf.gen.gogo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1alpha1/orm.proto=github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1,Mibc/core/channel/v1/channel.proto=github.com/cosmos/ibc-go/v6/modules/core/04-channel/types
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true
32 changes: 32 additions & 0 deletions Dymension/dymension-starter/proto/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 9e88ecdd390f419081b79a917958d0f9
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: bee5511075b7499da6178d9e4aaa628b
digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952
- remote: buf.build
owner: cosmos
repository: ibc
commit: a930cbf9d19a41b1bde5a51c78d5e4cd
digest: shake256:492f04bf9b220ffda848a70ec1824fccaefbf94cefbd1a3cddce6920d54bf47b3b51218699b6edc2d710eb922c99baa4c31d75ebb494f08b01a376ef350d03fb
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 28151c0d0a1641bf938a7672c500e01d
digest: shake256:49215edf8ef57f7863004539deff8834cfb2195113f0b890dd1f67815d9353e28e668019165b9d872395871eeafcbab3ccfdb2b5f11734d3cca95be9e8d139de
- remote: buf.build
owner: protocolbuffers
repository: wellknowntypes
commit: 657250e6a39648cbb169d079a60bd9ba
digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb
Loading

0 comments on commit a571888

Please sign in to comment.