https://github.com/terra-money/terraswap-graph
Terraswap Indexer + GraphQL
https://github.com/terra-money/terraswap-graph
Last synced: 6 months ago
JSON representation
Terraswap Indexer + GraphQL
- Host: GitHub
- URL: https://github.com/terra-money/terraswap-graph
- Owner: terra-money
- License: apache-2.0
- Created: 2021-07-21T12:52:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-29T15:19:27.000Z (about 2 years ago)
- Last Synced: 2024-04-14T22:52:31.339Z (over 1 year ago)
- Language: TypeScript
- Size: 236 KB
- Stars: 24
- Watchers: 6
- Forks: 27
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terraswap Graph
## Modules
* ### Indexer
* Get tx logs from mantle (https://hive.terra.dev/graphql) and store terraswap relative data into the database
* Collect hourly/daily reserve, volume and transaction count of each pairs
* Collect recent 24 hours swap data to serve recent volume
* Collect minutely exchage rate of each pairs
* Collect tx_history
## Prerequisites
1. Node.js >= 14.15.x
2. PostgreSQL == 13.x
## Setup
1. Clone
```zsh
$ git clone https://github.com/terra-money/terraswap-graph.git
```
2. Install packages
```zsh
$ npm install
```
3. Setup the database
* Install postgreSQL
* create a database
```psql
postgres => CREATE DATABASE terraswap-graph OWNER alice
```
4. set **ormconfig.js**
```javascript
const { DefaultNamingStrategy } = require('typeorm')
const { values, snakeCase } = require('lodash')
const entities = require('orm/entities')
class CamelToSnakeNamingStrategy extends DefaultNamingStrategy {
tableName(targetName, userSpecifiedName) {
return userSpecifiedName ? userSpecifiedName : snakeCase(targetName)
}
columnName(propertyName, customName, embeddedPrefixes) {
return snakeCase(embeddedPrefixes.concat(customName ? customName : propertyName).join('_'))
}
columnNameCustomized(customName) {
return customName
}
relationName(propertyName) {
return snakeCase(propertyName)
}
}
const connectionOptions = {
host: 'localhost',
port: 5432,
username: 'alice',
password: 'password',
database: 'terraswap-graph',
}
module.exports = [
{
name: 'default',
type: 'postgres',
synchronize: false,
migrationsRun: true,
logging: false,
logger: 'file',
migrations: ['src/orm/migrations/*.ts'],
...connectionOptions,
},
{
name: 'migration',
type: 'postgres',
synchronize: false,
migrationsRun: true,
logging: true,
logger: 'file',
supportBigNumbers: true,
bigNumberStrings: true,
entities: values(entities),
migrations: ['src/orm/migrations/*.ts'],
namingStrategy: new CamelToSnakeNamingStrategy(),
...connectionOptions,
},
]
```
5. Set .envrc
about .envrc - https://direnv.net/
.envrc (sample)
```
TZ='UTC'
export TERRA_LCD='https://lcd.terra.dev'
export TERRA_CHAIN_ID='columbus-5'
export TERRA_MANTLE='https://hive.terra.dev/graphql'
export START_BLOCK_HEIGHT=549000
```
## Run Modules
* ### Collector
```zsh
$ npm run collect
```
* ### GraphQL
```zsh
$ npm start
```