terra-money / fcd-classic

Terra ETL + RestFul API Server
https://fcd.terra.dev/swagger
MIT License
63 stars 40 forks source link

Terra FCD

Banner

Modules

Prerequisites

  1. Node.js version 14 or later
  2. PostgreSQL version 12 or later

Terra Core

  1. Setup a LCD
  2. Configure firewall (Reference)

Project setup

1. Clone

$ git clone https://github.com/terra-money/fcd.git

2. Install packages

npm i

3. Setup the database

FCD requires PostgreSQL as a backend database and TypeORM as an ORM.

Create a new database for FCD

postgres=> CREATE DATABASED fcd OWNER terra;

Synchronize Database Scheme

Table schema has to be synced before running Collector by setting synchronize to true. There is many way to configure TypeORM. Example is below:

ormconfig.js

module.exports = {
  name: 'default',
  type: 'postgres',
  host: 'localhost',
  database: 'fcd',
  username: 'terra',
  password: '<password>',
  synchronize: true
}

You shall not use CLI method, and it is good to disable synchronize option after the first sync.

4. Configure Environment Variables

Name Description Default Module(s)
CHAIN_ID Chain ID of Terra network bombay-12 API, Collector
INITIAL_HEIGHT The initial height of network. (Define 4724001 for Columbus-5) Collector
LCD_URI LCD URI for Terra network https://bombay-lcd.terra.dev API, Collector
RPC_URI RPC URI for Terra network required: http://x.x.x.x:26657 API, Collector
USE_LOG_FILE Write logs to logs directory false API, Collector
SENTRY_DSN Sentry DSN for error management (optional) API, Collector
SERVER_PORT Listening port for API server 3060 API
FCD_URI FCD URI for Terra network https://bombay-fcd.terra.dev API
BYPASS_URI Terra LCD address https://bombay-lcd.terra.dev API
MIRROR_GRAPH_URI Mirror GraphQL endpoint https://bombay-graph.mirror.finance/graphql API
PYLON_API_ENDPOINT Pylon API endpoint https://api.dev.pylon.rocks/api API
STATION_STATUS_JSON URL for Station version control https://terra.money/station/version-web.json API
ACTIVE_DENOMS Active Denominations ["uluna","usdr","ukrw","uusd","umnt"] API
ACTIVE_CURRENCY Active Currencies ["luna","sdt","krt","ust","mnt"] API
DISABLE_API Disable REST APIs false API
EXCLUDED_ROUTES List of regular expression string for excluding routes [] API
MIN_GAS_PRICES Minimum gas price by denom object {"uluna": "0.015", "usdr": "0.015", "uusd": "0.015", "ukrw": "0.015", "umnt": "0.015"} API
TOKEN_NETWORK Network specifier for whitelisted tokens required: mainnet / testnet API

In Terra, we use direnv for managing environment variable for development. See sample of .envrc

Running modules

Developement

Production

APIDoc & Swagger

apiDoc (https://apidocjs.com)

Swagger 2.0 (https://swagger.io)

Generate swagger for AWS api gateway

npm run swagger -- --apigateway

Generate combined swagger for lcd and fcd

npm run mergeswagger -- -o filename

Find LocalTerra to run whole ecosystem locally

https://github.com/terra-money/localterra